/
component.go
197 lines (168 loc) · 6.37 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
Copyright (C) 2018 OpenControl Contributors. See LICENSE.md for license.
*/
package component
import (
"sort"
"github.com/blang/semver"
"github.com/fatih/set"
"github.com/opencontrol/compliance-masonry/pkg/lib/common"
)
// 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"`
ResponsibleRole string `yaml:"responsible_role" json:"responsible_role"`
SchemaVersion semver.Version `yaml:"-" json:"-"`
}
// GetName returns the name of the component
func (c Component) GetName() string {
return c.Name
}
// GetKey returns the key for the component (may not be unique). Useful for creating directories.
func (c Component) GetKey() string {
return c.Key
}
// SetKey sets the key for the component. Useful for overriding.
func (c *Component) SetKey(key string) {
c.Key = key
}
// GetVerifications get all the verifications.
func (c Component) GetVerifications() *common.VerificationReferences {
return &c.Verifications
}
// GetReferences get all the references.
func (c Component) GetReferences() *common.GeneralReferences {
return &c.References
}
// GetAllSatisfies gets all the Satisfies objects for the component.
func (c Component) GetAllSatisfies() []common.Satisfies {
// Have to do manual conversion from this Component's Satisfies to the interface base.Satisfies.
baseSatisfies := make([]common.Satisfies, len(c.Satisfies))
for idx, value := range c.Satisfies {
baseSatisfies[idx] = value
}
return baseSatisfies
}
// GetVersion returns the version
func (c Component) GetVersion() semver.Version {
return c.SchemaVersion
}
// SetVersion sets the version for the component.
func (c *Component) SetVersion(version semver.Version) {
c.SchemaVersion = version
}
// GetResponsibleRole gets the responsible party / role for the component.
func (c Component) GetResponsibleRole() string {
return c.ResponsibleRole
}
// 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 []NarrativeSection `yaml:"narrative" json:"narrative"`
CoveredBy common.CoveredByList `yaml:"covered_by" json:"covered_by"`
Parameters []Section `yaml:"parameters" json:"parameters"`
ControlOrigin string `yaml:"control_origin" json:"control_origin"`
ControlOrigins []string `yaml:"control_origins" json:"control_origins"`
ImplementationStatus string `yaml:"implementation_status" json:"implementation_status"`
ImplementationStatuses []string `yaml:"implementation_statuses" json:"implementation_statuses"`
}
// GetControlKey returns the control
func (s Satisfies) GetControlKey() string {
return s.ControlKey
}
// GetStandardKey returns the standard
func (s Satisfies) GetStandardKey() string {
return s.StandardKey
}
// GetNarratives gets all the general documentation for this particular standard and control
func (s Satisfies) GetNarratives() []common.Section {
// Have to do manual conversion to the interface base.Section from NarrativeSection.
baseSection := make([]common.Section, len(s.Narrative))
for idx, value := range s.Narrative {
baseSection[idx] = value
}
return baseSection
}
// GetParameters gets all the parameters for this particular standard and control
func (s Satisfies) GetParameters() []common.Section {
// Have to do manual conversion to the interface base.Section from Section.
baseSection := make([]common.Section, len(s.Parameters))
for idx, value := range s.Parameters {
baseSection[idx] = value
}
return baseSection
}
// GetCoveredBy gets the list of all the CoveredBy
func (s Satisfies) GetCoveredBy() common.CoveredByList {
return s.CoveredBy
}
// GetControlOrigin returns the control origin (only the first one if multiple)
func (s Satisfies) GetControlOrigin() string {
return s.ControlOrigin
}
// GetControlOrigins returns all the control origins
func (s Satisfies) GetControlOrigins() []string {
controlOrigins := set.New(set.ThreadSafe)
for i := range s.ControlOrigins {
controlOrigins.Add(s.ControlOrigins[i])
}
if s.ControlOrigin != "" {
controlOrigins.Add(s.ControlOrigin)
}
l := set.StringSlice(controlOrigins)
sort.Strings(l)
return l
}
// GetImplementationStatus returns the implementation status (only the first one if multiple)
func (s Satisfies) GetImplementationStatus() string {
return s.ImplementationStatus
}
// GetImplementationStatuses returns all implementation statuses
func (s Satisfies) GetImplementationStatuses() []string {
implementationStatuses := set.New(set.ThreadSafe)
for i := range s.ImplementationStatuses {
implementationStatuses.Add(s.ImplementationStatuses[i])
}
if s.ImplementationStatus != "" {
implementationStatuses.Add(s.ImplementationStatus)
}
l := set.StringSlice(implementationStatuses)
sort.Strings(l)
return l
}
// NarrativeSection contains the key and text for a particular section.
// NarrativeSection can omit the key.
type NarrativeSection struct {
Key string `yaml:"key,omitempty" json:"key,omitempty"`
Text string `yaml:"text" json:"text"`
}
// GetKey returns a unique key
func (ns NarrativeSection) GetKey() string {
return ns.Key
}
// GetText returns the text for the section
func (ns NarrativeSection) GetText() string {
return ns.Text
}
// Section contains the key and text for a particular section. Both are required.
type Section struct {
Key string `yaml:"key" json:"key"`
Text string `yaml:"text" json:"text"`
}
// GetKey returns a unique key
func (s Section) GetKey() string {
return s.Key
}
// GetText returns the text for the section
func (s Section) GetText() string {
return s.Text
}