-
Notifications
You must be signed in to change notification settings - Fork 1
/
file_context.go
61 lines (51 loc) · 1.49 KB
/
file_context.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 parser
import (
defsecTypes "github.com/aquasecurity/defsec/pkg/types"
)
type SourceFormat string
const (
YamlSourceFormat SourceFormat = "yaml"
JsonSourceFormat SourceFormat = "json"
)
type FileContexts []*FileContext
type FileContext struct {
filepath string
lines []string
SourceFormat SourceFormat
Parameters map[string]*Parameter `json:"Parameters" yaml:"Parameters"`
Resources map[string]*Resource `json:"Resources" yaml:"Resources"`
Globals map[string]*Resource `json:"Globals" yaml:"Globals"`
Mappings map[string]interface{} `json:"Mappings,omitempty" yaml:"Mappings"`
Conditions map[string]Property `json:"Conditions,omitempty" yaml:"Conditions"`
}
func (t *FileContext) GetResourceByLogicalID(name string) *Resource {
for n, r := range t.Resources {
if name == n {
return r
}
}
return nil
}
func (t *FileContext) GetResourcesByType(names ...string) []*Resource {
var resources []*Resource
for _, r := range t.Resources {
for _, name := range names {
if name == r.Type() {
//
resources = append(resources, r)
}
}
}
return resources
}
func (t *FileContext) Metadata() defsecTypes.Metadata {
rng := defsecTypes.NewRange(t.filepath, 1, len(t.lines), "", nil)
return defsecTypes.NewMetadata(rng, NewCFReference("Template", rng).String())
}
func (t *FileContext) OverrideParameters(params map[string]any) {
for key := range t.Parameters {
if val, ok := params[key]; ok {
t.Parameters[key].UpdateDefault(val)
}
}
}