github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/arm/parser/template.go (about) 1 package parser 2 3 import ( 4 types2 "github.com/khulnasoft-lab/defsec/pkg/scanners/azure" 5 "github.com/khulnasoft-lab/defsec/pkg/scanners/azure/arm/parser/armjson" 6 "github.com/khulnasoft-lab/defsec/pkg/types" 7 ) 8 9 type Template struct { 10 Metadata types.Metadata `json:"-"` 11 Schema types2.Value `json:"$schema"` 12 ContentVersion types2.Value `json:"contentVersion"` 13 APIProfile types2.Value `json:"apiProfile"` 14 Parameters map[string]Parameter `json:"parameters"` 15 Variables map[string]types2.Value `json:"variables"` 16 Functions []Function `json:"functions"` 17 Resources []Resource `json:"resources"` 18 Outputs map[string]types2.Value `json:"outputs"` 19 } 20 21 type Parameter struct { 22 Metadata types.Metadata 23 Type types2.Value `json:"type"` 24 DefaultValue types2.Value `json:"defaultValue"` 25 MaxLength types2.Value `json:"maxLength"` 26 MinLength types2.Value `json:"minLength"` 27 } 28 29 type Function struct{} 30 31 type Resource struct { 32 Metadata types.Metadata `json:"-"` 33 innerResource 34 } 35 36 func (t *Template) SetMetadata(m *types.Metadata) { 37 t.Metadata = *m 38 } 39 40 func (r *Resource) SetMetadata(m *types.Metadata) { 41 r.Metadata = *m 42 } 43 44 func (p *Parameter) SetMetadata(m *types.Metadata) { 45 p.Metadata = *m 46 } 47 48 type innerResource struct { 49 APIVersion types2.Value `json:"apiVersion"` 50 Type types2.Value `json:"type"` 51 Kind types2.Value `json:"kind"` 52 Name types2.Value `json:"name"` 53 Location types2.Value `json:"location"` 54 Tags types2.Value `json:"tags"` 55 Sku types2.Value `json:"sku"` 56 Properties types2.Value `json:"properties"` 57 Resources []Resource `json:"resources"` 58 } 59 60 func (v *Resource) UnmarshalJSONWithMetadata(node armjson.Node) error { 61 62 if err := node.Decode(&v.innerResource); err != nil { 63 return err 64 } 65 66 v.Metadata = node.Metadata() 67 68 for _, comment := range node.Comments() { 69 var str string 70 if err := comment.Decode(&str); err != nil { 71 return err 72 } 73 // TODO 74 // v.Metadata.Comments = append(v.Metadata.Comments, str) 75 } 76 77 return nil 78 }