11package parser
22
33import (
4+ "encoding/base64"
45 "fmt"
56 "strconv"
7+ "time"
68
79 "gopkg.in/yaml.v3"
10+
11+ "github.com/aquasecurity/trivy/pkg/log"
812)
913
1014type TagType string
1115
1216const (
13- TagBool TagType = "!!bool"
14- TagInt TagType = "!!int"
15- TagFloat TagType = "!!float"
16- TagStr TagType = "!!str"
17- TagString TagType = "!!string"
18- TagSlice TagType = "!!seq"
19- TagMap TagType = "!!map"
17+ TagBool TagType = "!!bool"
18+ TagInt TagType = "!!int"
19+ TagFloat TagType = "!!float"
20+ TagStr TagType = "!!str"
21+ TagString TagType = "!!string"
22+ TagSlice TagType = "!!seq"
23+ TagMap TagType = "!!map"
24+ TagTimestamp TagType = "!!timestamp"
25+ TagBinary TagType = "!!binary"
2026)
2127
2228type ManifestNode struct {
@@ -33,8 +39,14 @@ func (r *ManifestNode) ToRego() any {
3339 return nil
3440 }
3541 switch r .Type {
36- case TagBool , TagInt , TagString , TagStr :
42+ case TagBool , TagInt , TagFloat , TagString , TagStr , TagBinary :
3743 return r .Value
44+ case TagTimestamp :
45+ t , ok := r .Value .(time.Time )
46+ if ! ok {
47+ return nil
48+ }
49+ return t .Format (time .RFC3339 )
3850 case TagSlice :
3951 var output []any
4052 for _ , node := range r .Value .([]ManifestNode ) {
@@ -58,40 +70,53 @@ func (r *ManifestNode) ToRego() any {
5870}
5971
6072func (r * ManifestNode ) UnmarshalYAML (node * yaml.Node ) error {
61-
6273 r .StartLine = node .Line
6374 r .EndLine = node .Line
6475 r .Type = TagType (node .Tag )
6576
6677 switch TagType (node .Tag ) {
6778 case TagString , TagStr :
68-
6979 r .Value = node .Value
7080 case TagInt :
7181 val , err := strconv .Atoi (node .Value )
7282 if err != nil {
73- return err
83+ return fmt . Errorf ( "failed to parse int: %w" , err )
7484 }
7585 r .Value = val
7686 case TagFloat :
7787 val , err := strconv .ParseFloat (node .Value , 64 )
7888 if err != nil {
79- return err
89+ return fmt . Errorf ( "failed to parse float: %w" , err )
8090 }
8191 r .Value = val
8292 case TagBool :
8393 val , err := strconv .ParseBool (node .Value )
8494 if err != nil {
85- return err
95+ return fmt .Errorf ("failed to parse bool: %w" , err )
96+ }
97+ r .Value = val
98+ case TagTimestamp :
99+ var val time.Time
100+ if err := node .Decode (& val ); err != nil {
101+ return fmt .Errorf ("failed to decode timestamp: %w" , err )
102+ }
103+ r .Value = val
104+ case TagBinary :
105+ val , err := base64 .StdEncoding .DecodeString (node .Value )
106+ if err != nil {
107+ return fmt .Errorf ("failed to decode binary data: %w" , err )
86108 }
87109 r .Value = val
88110 case TagMap :
89111 return r .handleMapTag (node )
90112 case TagSlice :
91113 return r .handleSliceTag (node )
92-
93114 default :
94- return fmt .Errorf ("node tag is not supported %s" , node .Tag )
115+ log .WithPrefix ("k8s" ).Debug ("Skipping unsupported node tag" ,
116+ log .String ("tag" , node .Tag ),
117+ log .FilePath (r .Path ),
118+ log .Int ("line" , node .Line ),
119+ )
95120 }
96121 return nil
97122}
0 commit comments