Skip to content

Commit b4e8c1e

Browse files
committed
feat: helper functions for control catalogs
Signed-off-by: Eddie Knight <knight@linux.com>
1 parent 4c950b2 commit b4e8c1e

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

control_yaml.go renamed to control.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,13 @@ func (c *Control) UnmarshalYAML(data []byte) error {
4343

4444
return nil
4545
}
46+
47+
func (c *Control) GetMappingReferences() (refs []string) {
48+
for _, ref := range c.Guidelines {
49+
refs = append(refs, ref.ReferenceId)
50+
}
51+
for _, ref := range c.Threats {
52+
refs = append(refs, ref.ReferenceId)
53+
}
54+
return refs
55+
}
Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package gemara
22

3-
import "github.com/goccy/go-yaml"
3+
import (
4+
"slices"
5+
6+
"github.com/goccy/go-yaml"
7+
)
48

59
// UnmarshalYAML allows decoding control catalogs from older/alternate YAML schemas.
610
// It supports mapping `families` -> `groups`.
@@ -38,3 +42,30 @@ func (c *ControlCatalog) UnmarshalYAML(data []byte) error {
3842

3943
return nil
4044
}
45+
46+
func (c *ControlCatalog) GetGroupNames() (groups []string) {
47+
for _, group := range c.Groups {
48+
groups = append(groups, group.Title)
49+
}
50+
return groups
51+
}
52+
53+
func (c *ControlCatalog) GetControlsForGroup(group string) (controls []Control) {
54+
for _, control := range c.Controls {
55+
if control.Group == group {
56+
controls = append(controls, control)
57+
}
58+
}
59+
return controls
60+
}
61+
62+
func (c *ControlCatalog) GetRequirementForApplicability(applicability string) (reqs []AssessmentRequirement) {
63+
for _, control := range c.Controls {
64+
for _, assessment := range control.AssessmentRequirements {
65+
if slices.Contains(assessment.Applicability, applicability) {
66+
reqs = append(reqs, assessment)
67+
}
68+
}
69+
}
70+
return reqs
71+
}

0 commit comments

Comments
 (0)