@@ -13,7 +13,7 @@ import (
13
13
oscal112 "github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-2"
14
14
15
15
"github.com/oscal-compass/oscal-sdk-go/extensions"
16
- . "github.com/oscal-compass/oscal-sdk-go/rules/ internal"
16
+ "github.com/oscal-compass/oscal-sdk-go/internal/set "
17
17
)
18
18
19
19
var (
27
27
ErrComponentsNotFound = errors .New ("no components not found" )
28
28
)
29
29
30
- /*
31
- MemoryStore provides implementation of a memory-based rule.Store.
32
- WARNING: This implementation is not thread safe.
33
- */
30
+ // MemoryStore implements the Store interface using an in-memory map-based data structure.
31
+ // WARNING: This implementation is not thread safe.
34
32
type MemoryStore struct {
35
33
// nodes saves the rule ID map keys, which are used with
36
34
// the other fields.
@@ -44,48 +42,50 @@ type MemoryStore struct {
44
42
45
43
// rulesByComponent stores the component title of any component
46
44
// mapped to any relevant rules.
47
- rulesByComponent map [string ]Set [string ]
45
+ rulesByComponent map [string ]set. Set [string ]
48
46
// checksByValidationComponent store checkId mapped to validation
49
47
// component title to filter check information on rules.
50
- checksByValidationComponent map [string ]Set [string ]
48
+ checksByValidationComponent map [string ]set. Set [string ]
51
49
}
52
50
53
- // NewMemoryStoreFromComponents creates a new memory-based rule finder.
54
- func NewMemoryStoreFromComponents (components []oscal112.DefinedComponent ) (* MemoryStore , error ) {
55
- if len (components ) == 0 {
56
- return nil , fmt .Errorf ("failed to create memory store from components: %w" , ErrComponentsNotFound )
57
- }
58
- store := & MemoryStore {
51
+ // NewMemoryStore creates a new memory-based Store.
52
+ func NewMemoryStore () * MemoryStore {
53
+ return & MemoryStore {
59
54
nodes : make (map [string ]extensions.RuleSet ),
60
55
byCheck : make (map [string ]string ),
61
- rulesByComponent : make (map [string ]Set [string ]),
62
- checksByValidationComponent : make (map [string ]Set [string ]),
56
+ rulesByComponent : make (map [string ]set. Set [string ]),
57
+ checksByValidationComponent : make (map [string ]set. Set [string ]),
63
58
}
59
+ }
64
60
61
+ // IndexAll indexes rule information from OSCAL Components.
62
+ func (m * MemoryStore ) IndexAll (components []oscal112.DefinedComponent ) error {
63
+ if len (components ) == 0 {
64
+ return fmt .Errorf ("failed to index components: %w" , ErrComponentsNotFound )
65
+ }
65
66
for _ , component := range components {
66
- extractedRules := store .indexComponent (component )
67
+ extractedRules := m .indexComponent (component )
67
68
if len (extractedRules ) != 0 {
68
- store .rulesByComponent [component .Title ] = extractedRules
69
+ m .rulesByComponent [component .Title ] = extractedRules
69
70
}
70
71
}
71
-
72
- return store , nil
72
+ return nil
73
73
}
74
74
75
- func (m * MemoryStore ) indexComponent (component oscal112.DefinedComponent ) Set [string ] {
76
- rules := NewSet [string ]()
75
+ func (m * MemoryStore ) indexComponent (component oscal112.DefinedComponent ) set. Set [string ] {
76
+ rules := set . New [string ]()
77
77
if component .Props == nil {
78
78
return rules
79
79
}
80
80
81
81
// Catalog all registered check implementations by validation component for filtering in
82
82
// `rules.FindByComponent`.
83
- checkIds := NewSet [string ]()
83
+ checkIds := set . New [string ]()
84
84
85
85
// Each rule set is linked by a group id in the property remarks
86
86
byRemarks := groupPropsByRemarks (* component .Props )
87
87
for _ , propSet := range byRemarks {
88
- ruleIdProp , ok := findProp (extensions .RuleIdProp , propSet )
88
+ ruleIdProp , ok := getProp (extensions .RuleIdProp , propSet )
89
89
if ! ok {
90
90
continue
91
91
}
@@ -193,11 +193,3 @@ func (m *MemoryStore) FindByComponent(ctx context.Context, componentId string) (
193
193
194
194
return ruleSets , nil
195
195
}
196
-
197
- func (m * MemoryStore ) All (ctx context.Context ) ([]extensions.RuleSet , error ) {
198
- var ruleSets []extensions.RuleSet
199
- for _ , rule := range m .nodes {
200
- ruleSets = append (ruleSets , rule )
201
- }
202
- return ruleSets , nil
203
- }
0 commit comments