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