github.com/DataDog/datadog-agent/pkg/security/secl@v0.55.0-devel.0.20240517055856-10c4965fea94/compiler/generators/accessors/field_handlers.tmpl (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 2022-present Datadog, Inc. 5 // Code generated - DO NOT EDIT. 6 7 {{range .BuildTags }}//{{.}}{{end}} 8 9 package {{.Name}} 10 11 import ( 12 "time" 13 ) 14 15 // ResolveFields resolves all the fields associate to the event type. Context fields are automatically resolved. 16 func (ev *Event) ResolveFields() { 17 ev.resolveFields(false) 18 } 19 20 // ResolveFieldsForAD resolves all the fields associate to the event type. Context fields are automatically resolved. 21 func (ev *Event) ResolveFieldsForAD() { 22 ev.resolveFields(true) 23 } 24 25 func (ev *Event) resolveFields(forADs bool) { 26 {{ $uniqueResolvers := dict }} 27 // resolve context fields that are not related to any event type 28 {{- range $Key, $Field := .Fields}} 29 {{- if $Field.GettersOnly }} 30 {{continue}} 31 {{end}} 32 33 {{- if and (eq $Field.Event "*") }} 34 {{ $resolver := $Field | GetFieldHandler $.AllFields }} 35 {{ if and (ne $resolver "") (not (hasKey $uniqueResolvers $resolver)) }} 36 {{$Checks := $Field | GetChecks $.AllFields}} 37 {{if $Checks}} 38 {{ $CheckStr := "" }} 39 {{range $Check := $Checks}} 40 {{$Check = $Check | printf "ev.%s()"}} 41 {{if $CheckStr}} 42 {{$CheckStr = $Check | printf "%s && %s" $CheckStr}} 43 {{else}} 44 {{$CheckStr = $Check}} 45 {{end}} 46 {{end}} 47 48 if {{$CheckStr}} { 49 {{ $resolver | FieldADPrint $Field }} 50 {{ $_ := set $uniqueResolvers $resolver "" }} 51 } 52 {{else}} 53 {{ $resolver := $Field | GetFieldHandler $.AllFields }} 54 {{ if and (ne $resolver "") (not (hasKey $uniqueResolvers $resolver)) }} 55 {{ $resolver | FieldADPrint $Field }} 56 {{ $_ := set $uniqueResolvers $resolver "" }} 57 {{end}} 58 {{end}} 59 {{end}} 60 {{- end -}} 61 {{end}} 62 63 // resolve event specific fields 64 switch ev.GetEventType().String() { 65 {{- range $Name, $EventType := .EventTypes}} 66 {{- if (ne $Name "*") }} 67 case "{{$Name}}": 68 {{- range $Key, $FieldName := $EventType.Fields }} 69 {{- $Field := index $.Fields $FieldName }} 70 {{- if $Field.GettersOnly }} 71 {{continue}} 72 {{end}} 73 74 {{ $resolver := $Field | GetFieldHandler $.AllFields }} 75 {{ if ne $resolver "" }} 76 {{$Checks := $Field | GetChecks $.AllFields}} 77 {{if $Checks}} 78 {{ $CheckStr := "" }} 79 {{range $Check := $Checks}} 80 {{$Check = $Check | printf "ev.%s()"}} 81 {{if $CheckStr}} 82 {{$CheckStr = $Check | printf "%s && %s" $CheckStr}} 83 {{else}} 84 {{$CheckStr = $Check}} 85 {{end}} 86 {{end}} 87 88 if {{$CheckStr}} { 89 {{ $resolver | FieldADPrint $Field }} 90 } 91 {{else}} 92 {{ $resolver | FieldADPrint $Field }} 93 {{end}} 94 {{end}} 95 {{end}} 96 {{- end}} 97 {{end}} 98 } 99 } 100 101 type FieldHandlers interface { 102 {{$Handlers := .Fields | GetHandlers}} 103 {{range $Proto, $Impl := $Handlers}} 104 {{$Proto}} 105 {{end}} 106 107 // custom handlers not tied to any fields 108 ExtraFieldHandlers 109 } 110 111 type FakeFieldHandlers struct {} 112 113 {{$Handlers := .Fields | GetHandlers}} 114 {{range $Proto, $Impl := $Handlers}} 115 func (dfh *FakeFieldHandlers) {{$Proto}} {{$Impl}} 116 {{end}}