-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathremover.go
49 lines (42 loc) · 1.33 KB
/
remover.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package scimpatch
import (
"context"
"github.com/scim2/filter-parser/v2"
)
type remover struct{}
var removerInstance *remover
func (r *remover) Direct(ctx context.Context, scopedMap map[string]interface{}, scopedAttr string, value interface{}) bool {
if _, ok := scopedMap[scopedAttr]; ok {
delete(scopedMap, scopedAttr)
return true
}
return false
}
func (r *remover) ByValueExpressionForItem(ctx context.Context, scopedMaps []map[string]interface{}, expr filter.Expression, value interface{}) ([]map[string]interface{}, bool) {
changed := false
newValues := []map[string]interface{}{}
for _, oldValue := range scopedMaps {
if !isMatchExpression(oldValue, expr) {
newValues = append(newValues, oldValue)
} else {
changed = true
}
}
return newValues, changed
}
func (r *remover) ByValueExpressionForAttribute(ctx context.Context, scopedMaps []map[string]interface{}, expr filter.Expression, subAttr string, value interface{}) ([]map[string]interface{}, bool) {
changed := false
newValues := []map[string]interface{}{}
for _, oldValue := range scopedMaps {
if !isMatchExpression(oldValue, expr) {
newValues = append(newValues, oldValue)
} else {
if _, ok := oldValue[subAttr]; ok {
changed = true
delete(oldValue, subAttr)
}
newValues = append(newValues, oldValue)
}
}
return newValues, changed
}