forked from snyk/driftctl
/
schemas.go
49 lines (40 loc) · 1.07 KB
/
schemas.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
package resource
import (
"strings"
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform/configs/configschema"
)
type AttributeSchema struct {
ConfigSchema configschema.Attribute
JsonString bool
}
type Flags uint32
func (f Flags) HasFlag(flag Flags) bool {
return f&flag != 0
}
func (f *Flags) AddFlag(flag Flags) {
*f |= flag
}
type Schema struct {
ProviderVersion *version.Version
Flags Flags
SchemaVersion int64
Attributes map[string]AttributeSchema
NormalizeFunc func(res *Resource)
HumanReadableAttributesFunc func(res *Resource) map[string]string
DiscriminantFunc func(*Resource, *Resource) bool
}
func (s *Schema) IsComputedField(path []string) bool {
metadata, exist := s.Attributes[strings.Join(path, ".")]
if !exist {
return false
}
return metadata.ConfigSchema.Computed
}
func (s *Schema) IsJsonStringField(path []string) bool {
metadata, exist := s.Attributes[strings.Join(path, ".")]
if !exist {
return false
}
return metadata.JsonString
}