github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/providers/dockerfile/dockerfile.go (about) 1 package dockerfile 2 3 import ( 4 "reflect" 5 6 "github.com/khulnasoft-lab/defsec/pkg/rego/convert" 7 ) 8 9 // NOTE: we are currently preserving mixed case json here for backward compatibility 10 11 // Dockerfile represents a parsed Dockerfile 12 type Dockerfile struct { 13 Stages []Stage 14 } 15 16 type Stage struct { 17 Name string 18 Commands []Command 19 } 20 21 func (d Dockerfile) ToRego() interface{} { 22 return map[string]interface{}{ 23 "Stages": convert.SliceToRego(reflect.ValueOf(d.Stages)), 24 } 25 } 26 27 func (s Stage) ToRego() interface{} { 28 return map[string]interface{}{ 29 "Name": s.Name, 30 "Commands": convert.SliceToRego(reflect.ValueOf(s.Commands)), 31 } 32 } 33 34 // Command is the struct for each dockerfile command 35 type Command struct { 36 Cmd string 37 SubCmd string 38 Flags []string 39 Value []string 40 Original string 41 JSON bool 42 Stage int 43 Path string 44 StartLine int 45 EndLine int 46 } 47 48 func (c Command) ToRego() interface{} { 49 return map[string]interface{}{ 50 "Cmd": c.Cmd, 51 "SubCmd": c.SubCmd, 52 "Flags": c.Flags, 53 "Value": c.Value, 54 "Original": c.Original, 55 "JSON": c.JSON, 56 "Stage": c.Stage, 57 "Path": c.Path, 58 "StartLine": c.StartLine, 59 "EndLine": c.EndLine, 60 } 61 }