github.com/DataDog/datadog-agent/pkg/security/secl@v0.55.0-devel.0.20240517055856-10c4965fea94/compiler/eval/field.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 holds eval related files 7 package eval 8 9 import "errors" 10 11 // Field name 12 type Field = string 13 14 // FieldValueType represents the type of the value of a field 15 type FieldValueType int 16 17 // Field value types 18 const ( 19 ScalarValueType FieldValueType = 1 << 0 20 GlobValueType FieldValueType = 1 << 1 21 PatternValueType FieldValueType = 1 << 2 22 RegexpValueType FieldValueType = 1 << 3 23 BitmaskValueType FieldValueType = 1 << 4 24 VariableValueType FieldValueType = 1 << 5 25 IPNetValueType FieldValueType = 1 << 6 26 ) 27 28 // MarshalJSON returns the JSON encoding of the FieldValueType 29 func (t FieldValueType) MarshalJSON() ([]byte, error) { 30 s := t.String() 31 if s == "" { 32 return nil, errors.New("invalid field value type") 33 } 34 35 return []byte(`"` + s + `"`), nil 36 } 37 38 func (t FieldValueType) String() string { 39 switch t { 40 case ScalarValueType: 41 return "scalar" 42 case GlobValueType: 43 return "glob" 44 case PatternValueType: 45 return "pattern" 46 case RegexpValueType: 47 return "regex" 48 case BitmaskValueType: 49 return "bitmask" 50 case VariableValueType: 51 return "variable" 52 case IPNetValueType: 53 return "ip" 54 } 55 56 return "" 57 } 58 59 // FieldValue describes a field value with its type 60 type FieldValue struct { 61 Value interface{} 62 Type FieldValueType 63 }