getRefAttribute returns the corresponding attribute based on the given attribute path. e.g. - `userName` would return the `userName` attribute. - `name.givenName` would return the `givenName` attribute. - `ext:employeeNumber` would return the `employeeNumber` attribute from the extension.
(attrPath filter.AttributePath)
| 116 | // - `name.givenName` would return the `givenName` attribute. |
| 117 | // - `ext:employeeNumber` would return the `employeeNumber` attribute from the extension. |
| 118 | func (v OperationValidator) getRefAttribute(attrPath filter.AttributePath) (*schema.CoreAttribute, error) { |
| 119 | // Get the corresponding schema, this can be the main schema or an extension. |
| 120 | var refSchema = v.schema |
| 121 | if uri := attrPath.URI(); uri != "" { |
| 122 | // It can also be an extension if it has a uri prefix. |
| 123 | var ok bool |
| 124 | if refSchema, ok = v.schemas[uri]; !ok { |
| 125 | return nil, fmt.Errorf("invalid uri prefix: %s", uri) |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Get the correct attribute corresponding to the given attribute path. |
| 130 | var ( |
| 131 | refAttr *schema.CoreAttribute |
| 132 | attrName = attrPath.AttributeName |
| 133 | ) |
| 134 | for _, attr := range refSchema.Attributes { |
| 135 | if strings.EqualFold(attr.Name(), attrName) { |
| 136 | refAttr = &attr |
| 137 | break |
| 138 | } |
| 139 | } |
| 140 | if refAttr == nil { |
| 141 | return nil, fmt.Errorf("could not find attribute %s", v.Path) |
| 142 | } |
| 143 | if subAttrName := attrPath.SubAttributeName(); subAttrName != "" { |
| 144 | refSubAttr, err := v.getRefSubAttribute(refAttr, subAttrName) |
| 145 | if err != nil { |
| 146 | return nil, err |
| 147 | } |
| 148 | refAttr = refSubAttr |
| 149 | } |
| 150 | return refAttr, nil |
| 151 | } |
| 152 | |
| 153 | // getRefSubAttribute returns the sub-attribute of the reference attribute that matches the given subAttrName, if none |
| 154 | // are found it will return an error. |