github.com/DataDog/datadog-agent/pkg/security/secl@v0.55.0-devel.0.20240517055856-10c4965fea94/compiler/eval/oo_case_insensitive.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  	// CaseInsensitiveCmp lower case values before comparing. Important : this operator override doesn't support approvers
    10  	CaseInsensitiveCmp = &OpOverrides{
    11  		StringEquals: func(a *StringEvaluator, b *StringEvaluator, state *State) (*BoolEvaluator, error) {
    12  			if a.Field != "" {
    13  				a.StringCmpOpts.CaseInsensitive = true
    14  			} else if b.Field != "" {
    15  				b.StringCmpOpts.CaseInsensitive = true
    16  			}
    17  
    18  			return StringEquals(a, b, state)
    19  		},
    20  		StringValuesContains: func(a *StringEvaluator, b *StringValuesEvaluator, state *State) (*BoolEvaluator, error) {
    21  			if a.Field != "" {
    22  				a.StringCmpOpts.CaseInsensitive = true
    23  			}
    24  
    25  			return StringValuesContains(a, b, state)
    26  		},
    27  		StringArrayContains: func(a *StringEvaluator, b *StringArrayEvaluator, state *State) (*BoolEvaluator, error) {
    28  			if a.Field != "" {
    29  				a.StringCmpOpts.CaseInsensitive = true
    30  			} else if b.Field != "" {
    31  				b.StringCmpOpts.CaseInsensitive = true
    32  			}
    33  
    34  			return StringArrayContains(a, b, state)
    35  		},
    36  		StringArrayMatches: func(a *StringArrayEvaluator, b *StringValuesEvaluator, state *State) (*BoolEvaluator, error) {
    37  			if a.Field != "" {
    38  				a.StringCmpOpts.CaseInsensitive = true
    39  			}
    40  
    41  			return StringArrayMatches(a, b, state)
    42  		},
    43  	}
    44  
    45  	// WindowsPathCmp lower case values before comparing, converts patterns to globs, and normalizes path separators. Important : this operator override doesn't support approvers
    46  	WindowsPathCmp = &OpOverrides{
    47  		StringEquals: func(a *StringEvaluator, b *StringEvaluator, state *State) (*BoolEvaluator, error) {
    48  			if a.Field != "" {
    49  				a.StringCmpOpts.CaseInsensitive = true
    50  				a.StringCmpOpts.PathSeparatorNormalize = true
    51  			} else if b.Field != "" {
    52  				b.StringCmpOpts.CaseInsensitive = true
    53  				b.StringCmpOpts.PathSeparatorNormalize = true
    54  			}
    55  
    56  			return GlobCmp.StringEquals(a, b, state)
    57  		},
    58  		StringValuesContains: func(a *StringEvaluator, b *StringValuesEvaluator, state *State) (*BoolEvaluator, error) {
    59  			if a.Field != "" {
    60  				a.StringCmpOpts.CaseInsensitive = true
    61  				a.StringCmpOpts.PathSeparatorNormalize = true
    62  			}
    63  
    64  			return GlobCmp.StringValuesContains(a, b, state)
    65  		},
    66  		StringArrayContains: func(a *StringEvaluator, b *StringArrayEvaluator, state *State) (*BoolEvaluator, error) {
    67  			if a.Field != "" {
    68  				a.StringCmpOpts.CaseInsensitive = true
    69  				a.StringCmpOpts.PathSeparatorNormalize = true
    70  			} else if b.Field != "" {
    71  				b.StringCmpOpts.CaseInsensitive = true
    72  				b.StringCmpOpts.PathSeparatorNormalize = true
    73  			}
    74  
    75  			return GlobCmp.StringArrayContains(a, b, state)
    76  		},
    77  		StringArrayMatches: func(a *StringArrayEvaluator, b *StringValuesEvaluator, state *State) (*BoolEvaluator, error) {
    78  			if a.Field != "" {
    79  				a.StringCmpOpts.CaseInsensitive = true
    80  				a.StringCmpOpts.PathSeparatorNormalize = true
    81  			}
    82  
    83  			return GlobCmp.StringArrayMatches(a, b, state)
    84  		},
    85  	}
    86  )