MCPcopy Create free account
hub / github.com/elimity-com/scim / validateUpdate

Method validateUpdate

internal/patch/update.go:11–66  ·  view source on GitHub ↗

validateUpdate validates the add/replace operation contained within the validator based on on Section 3.5.2.1 in RFC 7644. More info: https://datatracker.ietf.org/doc/html/rfc7644#section-3.5.2.1

()

Source from the content-addressed store, hash-verified

9// validateUpdate validates the add/replace operation contained within the validator based on on Section 3.5.2.1 in
10// RFC 7644. More info: https://datatracker.ietf.org/doc/html/rfc7644#section-3.5.2.1
11func (v OperationValidator) validateUpdate() (interface{}, error) {
12 // The operation must contain a "value" member whose content specifies the value to be added/replaces.
13 if v.value == nil {
14 return nil, fmt.Errorf("an add operation must contain a value member")
15 }
16
17 // If "path" is omitted, the target location is assumed to be the resource itself.
18 if v.Path == nil {
19 return v.validateEmptyPath()
20 }
21
22 refAttr, err := v.getRefAttribute(v.Path.AttributePath)
23 if err != nil {
24 return nil, err
25 }
26 if v.Path.ValueExpression != nil {
27 if err := f.NewFilterValidator(v.Path.ValueExpression, schema.Schema{
28 Attributes: refAttr.SubAttributes(),
29 }).Validate(); err != nil {
30 return nil, err
31 }
32 }
33 if subAttrName := v.Path.SubAttributeName(); subAttrName != "" {
34 refSubAttr, err := v.getRefSubAttribute(refAttr, subAttrName)
35 if err != nil {
36 return nil, err
37 }
38 refAttr = refSubAttr
39 }
40
41 if !refAttr.MultiValued() {
42 attr, scimErr := refAttr.ValidateSingular(v.value)
43 if scimErr != nil {
44 return nil, scimErr
45 }
46 return attr, nil
47 }
48
49 if list, ok := v.value.([]interface{}); ok {
50 var attrs []interface{}
51 for _, value := range list {
52 attr, scimErr := refAttr.ValidateSingular(value)
53 if scimErr != nil {
54 return nil, scimErr
55 }
56 attrs = append(attrs, attr)
57 }
58 return attrs, nil
59 }
60
61 attr, scimErr := refAttr.ValidateSingular(v.value)
62 if scimErr != nil {
63 return nil, scimErr
64 }
65 return []interface{}{attr}, nil
66}

Callers 1

ValidateMethod · 0.95

Calls 7

validateEmptyPathMethod · 0.95
getRefAttributeMethod · 0.95
getRefSubAttributeMethod · 0.95
SubAttributesMethod · 0.80
MultiValuedMethod · 0.80
ValidateSingularMethod · 0.80
ValidateMethod · 0.45

Tested by

no test coverage detected