github.com/DataDog/datadog-agent/pkg/security/secl@v0.55.0-devel.0.20240517055856-10c4965fea94/compiler/eval/oo_glob_cmp.go (about) 1 // Unless explicitly stated otherwise all files in this repository are licensed 2 // under the Apache License Version 2.0. 3 // This product includes software developed at Datadog (https://www.datadoghq.com/). 4 // Copyright 2016-present Datadog, Inc. 5 6 package eval 7 8 var ( 9 // GlobCmp replaces a pattern matcher with a glob matcher for *file.path fields. 10 GlobCmp = &OpOverrides{ 11 StringEquals: func(a *StringEvaluator, b *StringEvaluator, state *State) (*BoolEvaluator, error) { 12 if a.ValueType == PatternValueType { 13 a.ValueType = GlobValueType 14 } else if b.ValueType == PatternValueType { 15 b.ValueType = GlobValueType 16 } 17 18 return StringEquals(a, b, state) 19 }, 20 StringValuesContains: func(a *StringEvaluator, b *StringValuesEvaluator, state *State) (*BoolEvaluator, error) { 21 if a.ValueType == PatternValueType { 22 a.ValueType = GlobValueType 23 } else { 24 var values StringValues 25 for _, v := range b.Values.GetFieldValues() { 26 if v.Type == PatternValueType { 27 v.Type = GlobValueType 28 } 29 values.AppendFieldValue(v) 30 } 31 b = &StringValuesEvaluator{ 32 Values: values, 33 } 34 } 35 36 return StringValuesContains(a, b, state) 37 }, 38 StringArrayContains: func(a *StringEvaluator, b *StringArrayEvaluator, state *State) (*BoolEvaluator, error) { 39 if a.ValueType == PatternValueType { 40 a.ValueType = GlobValueType 41 } 42 43 return StringArrayContains(a, b, state) 44 }, 45 StringArrayMatches: func(a *StringArrayEvaluator, b *StringValuesEvaluator, state *State) (*BoolEvaluator, error) { 46 var values StringValues 47 for _, v := range b.Values.GetFieldValues() { 48 if v.Type == PatternValueType { 49 v.Type = GlobValueType 50 } 51 values.AppendFieldValue(v) 52 } 53 b = &StringValuesEvaluator{ 54 Values: values, 55 } 56 57 return StringArrayMatches(a, b, state) 58 }, 59 } 60 )