forked from opencontrol/compliance-masonry
/
component.go
112 lines (90 loc) · 3.02 KB
/
component.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package component
import (
"github.com/opencontrol/compliance-masonry/models/components/versions/base"
"github.com/opencontrol/compliance-masonry/models/common"
"github.com/blang/semver"
)
// Component struct is an individual component requiring documentation
// Schema info: https://github.com/opencontrol/schemas#component-yaml
type Component struct {
Name string `yaml:"name" json:"name"`
Key string `yaml:"key" json:"key"`
References common.GeneralReferences `yaml:"references" json:"references"`
Verifications common.VerificationReferences `yaml:"verifications" json:"verifications"`
Satisfies []Satisfies `yaml:"satisfies" json:"satisfies"`
SchemaVersion semver.Version `yaml:"-" json:"-"`
}
func (c Component) GetName() string {
return c.Name
}
func (c Component) GetKey() string {
return c.Key
}
func (c *Component) SetKey(key string) {
c.Key = key
}
func (c Component) GetVerifications() *common.VerificationReferences {
return &c.Verifications
}
func (c Component) GetReferences() *common.GeneralReferences {
return &c.References
}
func (c Component) GetAllSatisfies() []base.Satisfies {
// Have to do manual conversion from this Component's Satisfies to the interface base.Satisfies.
baseSatisfies := make([]base.Satisfies, len(c.Satisfies))
for idx, value := range c.Satisfies {
baseSatisfies[idx] = value
}
return baseSatisfies
}
func (c Component) GetVersion() semver.Version {
return c.SchemaVersion
}
func (c *Component) SetVersion(version semver.Version) {
c.SchemaVersion = version
}
func (c Component) GetResponsibleRole() string {
return ""
}
// Satisfies struct contains data demonstrating why a specific component meets
// a control
// This struct is a one-to-one mapping of a `satisfies` item in the component.yaml schema
// https://github.com/opencontrol/schemas#component-yaml
type Satisfies struct {
ControlKey string `yaml:"control_key" json:"control_key"`
StandardKey string `yaml:"standard_key" json:"standard_key"`
Narrative Narrative `yaml:"narrative" json:"narrative"`
CoveredBy common.CoveredByList `yaml:"covered_by" json:"covered_by"`
}
func (s Satisfies) GetControlKey() string {
return s.ControlKey
}
func (s Satisfies) GetStandardKey() string {
return s.StandardKey
}
func (s Satisfies) GetNarratives() []base.Section {
// Have to do manual conversion to the interface base.Section.
// V2.0.0 only had one Narrative field, so if it actually exists, let's create a slice of 1 to return.
var baseNarrative []base.Section
if len(s.Narrative) > 0 {
baseNarrative = make([]base.Section, 1)
baseNarrative[0] = s.Narrative
}
return baseNarrative
}
func (s Satisfies) GetParameters() []base.Section {
return nil
}
func (s Satisfies) GetCoveredBy() common.CoveredByList {
return s.CoveredBy
}
func (s Satisfies) GetControlOrigin() string {
return ""
}
type Narrative string
func (n Narrative) GetKey() string {
return ""
}
func (n Narrative) GetText() string {
return string(n)
}