oscal 0.2.3 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/lib/oscal/v1_2_1/all_models.rb +16379 -0
  3. data/lib/oscal/v1_2_1.rb +109 -0
  4. data/lib/oscal/version.rb +1 -1
  5. data/lib/oscal/version_registry.rb +183 -0
  6. data/lib/oscal/versioned.rb +88 -0
  7. data/lib/oscal.rb +93 -3
  8. metadata +38 -111
  9. data/.docker/Dockerfile +0 -19
  10. data/.docker/Makefile +0 -43
  11. data/.docker/docker-compose.yml +0 -14
  12. data/.docker/readme.md +0 -61
  13. data/.github/workflows/rake.yml +0 -15
  14. data/.github/workflows/release.yml +0 -24
  15. data/.gitignore +0 -13
  16. data/.gitmodules +0 -3
  17. data/.hound.yml +0 -5
  18. data/.rspec +0 -2
  19. data/.rubocop.yml +0 -10
  20. data/.ruby-version +0 -1
  21. data/CODE_OF_CONDUCT.md +0 -84
  22. data/Gemfile +0 -16
  23. data/LICENSE +0 -25
  24. data/Makefile +0 -1
  25. data/README.adoc +0 -115
  26. data/Rakefile +0 -19
  27. data/bin/console +0 -30
  28. data/bin/rspec +0 -27
  29. data/bin/setup +0 -8
  30. data/docker-compose.yml +0 -1
  31. data/exe/convert2oscalyaml.rb +0 -560
  32. data/lib/oscal/add.rb +0 -26
  33. data/lib/oscal/address.rb +0 -22
  34. data/lib/oscal/address_line.rb +0 -11
  35. data/lib/oscal/alter.rb +0 -22
  36. data/lib/oscal/assembly.rb +0 -120
  37. data/lib/oscal/assessment_plan.rb +0 -28
  38. data/lib/oscal/assessment_result.rb +0 -230
  39. data/lib/oscal/attribute_type_hash.rb +0 -81
  40. data/lib/oscal/back_matter.rb +0 -20
  41. data/lib/oscal/base64_object.rb +0 -11
  42. data/lib/oscal/base_class.rb +0 -50
  43. data/lib/oscal/catalog.rb +0 -63
  44. data/lib/oscal/choice.rb +0 -11
  45. data/lib/oscal/citation.rb +0 -22
  46. data/lib/oscal/combine.rb +0 -11
  47. data/lib/oscal/common_utils.rb +0 -35
  48. data/lib/oscal/constraint.rb +0 -20
  49. data/lib/oscal/control.rb +0 -28
  50. data/lib/oscal/custom.rb +0 -22
  51. data/lib/oscal/datatypes.rb +0 -50
  52. data/lib/oscal/document_id.rb +0 -11
  53. data/lib/oscal/email_address.rb +0 -11
  54. data/lib/oscal/exclude_control.rb +0 -22
  55. data/lib/oscal/external_id.rb +0 -11
  56. data/lib/oscal/group.rb +0 -33
  57. data/lib/oscal/guideline.rb +0 -11
  58. data/lib/oscal/hash_object.rb +0 -11
  59. data/lib/oscal/import_object.rb +0 -22
  60. data/lib/oscal/include_control.rb +0 -22
  61. data/lib/oscal/insert_control.rb +0 -22
  62. data/lib/oscal/link.rb +0 -11
  63. data/lib/oscal/list.rb +0 -160
  64. data/lib/oscal/location.rb +0 -31
  65. data/lib/oscal/location_uuid.rb +0 -11
  66. data/lib/oscal/logger.rb +0 -12
  67. data/lib/oscal/matching.rb +0 -11
  68. data/lib/oscal/member_of_organization.rb +0 -11
  69. data/lib/oscal/merge.rb +0 -20
  70. data/lib/oscal/metadata_block.rb +0 -36
  71. data/lib/oscal/modify.rb +0 -22
  72. data/lib/oscal/parameter.rb +0 -31
  73. data/lib/oscal/parsing_functions.rb +0 -19
  74. data/lib/oscal/part.rb +0 -24
  75. data/lib/oscal/party.rb +0 -36
  76. data/lib/oscal/party_uuid.rb +0 -11
  77. data/lib/oscal/profile.rb +0 -37
  78. data/lib/oscal/property.rb +0 -11
  79. data/lib/oscal/remove.rb +0 -11
  80. data/lib/oscal/resource.rb +0 -29
  81. data/lib/oscal/responsible_party.rb +0 -24
  82. data/lib/oscal/revision.rb +0 -23
  83. data/lib/oscal/rlink.rb +0 -20
  84. data/lib/oscal/role.rb +0 -22
  85. data/lib/oscal/select.rb +0 -20
  86. data/lib/oscal/serializer.rb +0 -76
  87. data/lib/oscal/set_parameter.rb +0 -31
  88. data/lib/oscal/telephone_number.rb +0 -11
  89. data/lib/oscal/test.rb +0 -11
  90. data/lib/oscal/url.rb +0 -11
  91. data/lib/oscal/value.rb +0 -37
  92. data/lib/oscal/with_id.rb +0 -40
  93. data/oscal.gemspec +0 -30
  94. data/sig/oscal.rbs +0 -4
  95. data/spec/oscal/assessment_plan_spec.rb +0 -21
  96. data/spec/oscal/catalog_spec.rb +0 -42
  97. data/spec/oscal_spec.rb +0 -18
  98. data/spec/sample_inputs/import-ap.json +0 -4
  99. data/spec/spec_helper.rb +0 -15
@@ -1,120 +0,0 @@
1
- require_relative "parsing_functions"
2
- require_relative "logger"
3
- require_relative "metadata_block"
4
- require "json"
5
-
6
- module Oscal
7
- class MetadataBlockWrapper < Oscal::MetadataBlock
8
- include ParsingFunctions
9
- def initialize(metadata_hash)
10
- # MetadataBlock likes to get strings, but may sometimes get symbols
11
- # this little function makes sure it gets strings everytime
12
- super(metadata_hash.transform_keys { |key| sym2str(key) })
13
- end
14
- end
15
-
16
- class Assembly
17
- include Oscal::ParsingFunctions
18
- include Oscal::ParsingLogger
19
-
20
- def mandatory_attributes
21
- if self.class.constants.include?(:MANDATORY)
22
- self.class::MANDATORY
23
- else
24
- []
25
- end
26
- end
27
-
28
- def allowed_attributes
29
- if self.class.constants.include?(:OPTIONAL)
30
- mandatory_attributes + self.class::OPTIONAL
31
- else
32
- mandatory_attributes
33
- end
34
- end
35
-
36
- def to_json(*args)
37
- to_h.to_json(*args)
38
- end
39
-
40
- def to_h
41
- allowed_attributes.each_with_object({}) do |var, hash|
42
- attr_value = method(var).call
43
- hash[sym2str(var)] = if attr_value == nil
44
- next
45
- elsif attr_value.class <= OscalArray
46
- attr_value.each(&:to_h)
47
- elsif attr_value.class <= OscalDatatype
48
- attr_value
49
- else
50
- attr_value.to_h
51
- end
52
- end
53
- end
54
-
55
- def check_and_normalize_input(input)
56
- @logger.debug("Checking to see if input is a Hash")
57
- unless input.is_a? Hash
58
- raise Oscal::InvalidTypeError,
59
- "Assemblies can only be created from Hash types"
60
- end
61
- @logger.debug("Assembly is hash with keys #{input.keys}")
62
-
63
- @logger.debug("Attempting to transform strings to symbols.")
64
- # Transform the keys from Strings to Symbols
65
- input.transform_keys { |key| str2sym(key) }
66
- end
67
-
68
- def validate_input(input)
69
- @logger.debug("Checking mandatory and optional values.")
70
- missing_values?(mandatory_attributes, input)
71
- extra_values?(allowed_attributes, input)
72
- end
73
-
74
- def missing_values?(mandatory, provided)
75
- @logger.debug("Checking mandatory values: #{mandatory}")
76
- missing_values = mandatory - provided.keys.intersection(mandatory)
77
- if missing_values.length.positive?
78
- raise Oscal::InvalidTypeError,
79
- "Missing mandatory values: #{missing_values}"
80
- end
81
- end
82
-
83
- def extra_values?(allowed, provided)
84
- @logger.debug("Checking allowed values: #{allowed}")
85
- extra_values = provided.keys - provided.keys.intersection(allowed)
86
- if extra_values.length.positive?
87
- raise Oscal::InvalidTypeError,
88
- "Extra attributes provided #{extra_values}"
89
- end
90
- end
91
-
92
- def validate_content(key, value)
93
- @logger.info("Validating #{value}")
94
- expected_class = Oscal::get_type_of_attribute(key)
95
- @logger.debug("Attempting to instiate #{key} as #{expected_class}")
96
- instantiated = expected_class.new(value)
97
- rescue Oscal::InvalidTypeError
98
- raise Oscal::InvalidTypeError,
99
- "Value #{value.to_s[0, 25]} not a valid #{key}"
100
- else
101
- instantiated # Return the valid class
102
- end
103
-
104
- def initialize(input)
105
- @logger = get_logger
106
- @logger.debug("#{self.class}.new called with #{input.to_s[0, 25]}")
107
-
108
- # covert String:String to Symbol:String
109
- sym_hash = check_and_normalize_input(input)
110
-
111
- # Make sure all required and no extra keys are provided
112
- validate_input(sym_hash)
113
-
114
- # Attempt to convert each value to it's registered type
115
- sym_hash.each do |key, value|
116
- method("#{key}=".to_sym).call(validate_content(key, value))
117
- end
118
- end
119
- end
120
- end
@@ -1,28 +0,0 @@
1
- require_relative "assembly"
2
- require_relative "metadata_block"
3
- require_relative "datatypes"
4
-
5
- module Oscal
6
- module AssessmentPlan
7
- class ImportSSP < Assembly
8
- attr_accessor(*(MANDATORY = %i(href).freeze),
9
- *(OPTIONAL = %i(remarks).freeze))
10
- end
11
-
12
- class ReviewedControls < Assembly
13
- attr_accessor(*(MANDATORY = %i(control_selections).freeze),
14
- *(OPTIONAL = %i(description props links
15
- control_objective_selections
16
- remarks).freeze))
17
- end
18
-
19
- class AssessmentPlan < Assembly
20
- attr_accessor(*(MANDATORY = %i(uuid metadata import_ssp
21
- reviewed_controls).freeze),
22
- *(OPTIONAL = %i(local_definitions terms_and_conditions
23
- reviewed_controls assessment_subjects
24
- assessment_assets tasks
25
- back_matter).freeze))
26
- end
27
- end
28
- end
@@ -1,230 +0,0 @@
1
- require_relative "assembly"
2
- require_relative "metadata_block"
3
- require_relative "datatypes"
4
-
5
- module Oscal
6
- module AssessmentResult
7
- class Activity < Assembly
8
- attr_accessor(*(MANDATORY = %i(uuid).freeze),
9
- *(OPTIONAL = %i(title description props links steps
10
- related_controls responsible_roles
11
- remarks).freeze))
12
- end
13
-
14
- class Attestations < Assembly
15
- # TODO: Define this. Punting for the time being
16
- end
17
-
18
- class AssessmentAssets < Assembly
19
- attr_accessor(*(MANDATORY = %i(assessment_platforms).freeze),
20
- *(OPTIONAL = %i(components).freeze))
21
- end
22
-
23
- class AssessmentLog
24
- attr_accessor(*(MANDATORY = %i(entries).freeze))
25
- end
26
-
27
- class AssessmentPlatform < Assembly
28
- # TODO: Define this. Punting for the time being
29
- end
30
-
31
- class AssessmentTask < Assembly
32
- attr_accessor(*(MANDATORY = %i(uuid type title).freeze),
33
- *(OPTIONAL = %i(description props links timing dependencies
34
- tasks associated_activities subjects
35
- responsible_roles remarks).freeze))
36
- end
37
-
38
- class AssociatedActivity < Assembly
39
- attr_accessor(*(MANDATORY = %i(activity_uuid subjects).freeze),
40
- *(OPTIONAL = %i(props links responsible_roles
41
- remarks).freeze))
42
- end
43
-
44
- class AssociatedRisk < Assembly
45
- attr_accessor(*(MANDATORY = %i(risk_uuid).freeze))
46
- end
47
-
48
- class Attestation < Assembly
49
- # TODO: Define this. Punting for the time being
50
- end
51
-
52
- class Component < Assembly
53
- # TODO: Define this. Punting for the time being
54
- end
55
-
56
- class ControlObjectiveSelection < Assembly
57
- attr_accessor(*(OPTIONAL = %i(description props links include_all
58
- include_objectives exclude_objectives
59
- remarks).freeze))
60
- end
61
-
62
- class ControlSelection < Assembly
63
- attr_accessor(*(OPTIONAL = %i(description props links include_all
64
- include_controls exclude_controls
65
- remarks).freeze))
66
- end
67
-
68
- class Entry < Assembly
69
- # TODO: Define this. Punting for the time being
70
- end
71
-
72
- class ExcludeControl
73
- # TODO: Define this. Punting for the time being
74
- # NOTE: This has the same name as profile/exclude-control, but a different
75
- # definition!
76
- end
77
-
78
- class ExcludeObjective < Assembly
79
- attr_accessor(*(MANDATORY = %i(objective_id).freeze))
80
- end
81
-
82
- class Finding < Assembly
83
- attr_accessor(*(MANDATORY = %i(uuid title description target).freeze),
84
- *(OPTIONAL = %i(implementation_statement_uuid
85
- related_observations related_risks
86
- remarks).freeze))
87
- end
88
-
89
- class ImportAP < Assembly
90
- attr_accessor(*(MANDATORY = %i(href).freeze),
91
- *(OPTIONAL = %i(remarks).freeze))
92
- end
93
-
94
- class IncludeAll < Assembly
95
- # This is an Assembly that acts like a flag - it has no no contents
96
- end
97
-
98
- class IncludeControl < Assembly
99
- attr_accessor(*(MANDATORY = %i(control_id).freeze),
100
- *(OPTIONAL = %i(statement_ids).freeze))
101
- end
102
-
103
- class IncludeObjective < Assembly
104
- attr_accessor(*(MANDATORY = %i(objective_id).freeze))
105
- end
106
-
107
- class InventoryItem < Assembly
108
- # TODO: Define this. Punting for the time being
109
- end
110
-
111
- class LocalDefinitions < Assembly
112
- # NOTE we deviate fromt the spec here! local-definitions is defined twice
113
- # with different attributes. All attributes are optional, so we merge it
114
- # into one big back of optional attributes
115
- attr_accessor(*(OPTIONAL = %i(objectives_and_methods activities
116
- remarks components inventory_items users
117
- assesssment_assets tasks).freeze))
118
- end
119
-
120
- class ObjectivesAndMethods < Assembly
121
- attr_accessor(*(MANDATORY = %i(control_id parts).freeze),
122
- *(OPTIONAL = %i(description props links remarks).freeze))
123
- end
124
-
125
- class Observation < Assembly
126
- attr_accessor(*(MANDATORY = %i(uuid description methods collected).freeze),
127
- *(OPTIONAL = %i(title props links methods types origins
128
- subjects relevent_evidence expires
129
- remarks).freeze))
130
- end
131
-
132
- class RelatedControls < Assembly
133
- attr_accessor(*(MANDATORY = %i(control_selections).freeze),
134
- *(OPTIONAL = %i(description props links
135
- control_objective_selections
136
- remarks).freeze))
137
- end
138
-
139
- class RelatedObservation < Assembly
140
- attr_accessor(*(MANDATORY = %i(observation_uuid).freeze),
141
- *(OPTIONAL = %i().freeze))
142
- end
143
-
144
- class ResponsibleRole < Assembly
145
- attr_accessor(*(MANDATORY = %i(role_id).freeze),
146
- *(OPTIONAL = %i(props links party_uuids remarks).freeze))
147
- end
148
-
149
- class Result < Assembly
150
- attr_accessor(*(MANDATORY = %i(uuid title description start).freeze),
151
- *(OPTIONAL = %i(end props links local_definitions
152
- reviewed_controls attestations
153
- assessment_log observations risks findings
154
- remarks).freeze))
155
- end
156
-
157
- class ReviewedControls < Assembly
158
- attr_accessor(*(MANDATORY = %i(control_selections).freeze),
159
- *(OPTIONAL = %i(description props links
160
- control_objective_selections
161
- remarks).freeze))
162
- end
163
-
164
- class Risk < Assembly
165
- attr_accessor(*(MANDATORY = %i(uuid title description statement
166
- status).freeze),
167
- *(OPTIONAL = %i(propse links origins threat_ids
168
- characterizations mitigating_factors
169
- deadline remediations risk_log
170
- related_observations).freeze))
171
- end
172
-
173
- class Status
174
- # Status is defined twice, once as a datatype, once as an assembly
175
- # this class figures out which is which
176
- def initialize(input)
177
- if input.instance_of? String
178
- StatusString.new(input)
179
- elsif input.instance_of? Hash
180
- StatusAssembly.new(input)
181
- else
182
- raise Oscal::InvalidTypeError, "status must be a string or assembly"
183
- end
184
- end
185
- end
186
-
187
- class StatusString < TokenDataType
188
- end
189
-
190
- class StatusAssembly < Assembly
191
- attr_accessor(*(MANDATORY = %i(state).freeze),
192
- *(OPTIONAL = %i(reason remarks).freeze))
193
- end
194
-
195
- class Step < Assembly
196
- attr_accessor(*(MANDATORY = %i(uuid).freeze),
197
- *(OPTIONAL = %i(title description props links
198
- reviewed_controls responsible_roles
199
- remarks).freeze))
200
- end
201
-
202
- class Subject < Assembly
203
- attr_accessor(*(OPTIONAL = %i(subject_uuid type
204
- description props links include_all
205
- include_subjects exclude_subjects
206
- remarks).freeze))
207
- end
208
-
209
- class Target < Assembly
210
- attr_accessor(*(MANDATORY = %i(type target_id status).freeze),
211
- *(OPTIONAL = %i(title description props links
212
- implementation_status remarks).freeze))
213
- end
214
-
215
- class Task < Assembly
216
- # TODO: Define this. Punting for the time being
217
- end
218
-
219
- class User < Assembly
220
- # TODO: Define this. Punting for the time being
221
- end
222
-
223
- ##########################################
224
-
225
- class AssessmentResult < Assembly
226
- attr_accessor(*(MANDATORY = %i(uuid metadata import_ap results).freeze),
227
- *(OPTIONAL = %i(local_definitions back_matter).freeze))
228
- end
229
- end
230
- end
@@ -1,81 +0,0 @@
1
- require_relative("datatypes")
2
- require_relative("list")
3
-
4
- module Oscal
5
- ATTRIBUTE_TYPE_HASH = {
6
- activities: AssessmentResult::ActivityArray,
7
- activity_uuid: Uuid,
8
- assessment_plan: AssessmentPlan::AssessmentPlan,
9
- assessment_platforms: AssessmentResult::AssessmentPlatformArray,
10
- assessment_results: AssessmentResult::AssessmentResult,
11
- assessment_log: AssessmentResult::AssessmentLog,
12
- associated_activities: AssessmentResult::AssociatedActivityArray,
13
- attestations: AssessmentResult::AttestationArray,
14
- collected: DateTimeWithTimezoneDataType,
15
- components: AssessmentResult::ComponentArray,
16
- control_id: TokenDataType,
17
- control_objective_selections: AssessmentResult::ControlObjectiveSelectionArray,
18
- control_selections: AssessmentResult::ControlSelectionArray,
19
- description: MarkupMultilineDataType,
20
- end: DateTimeWithTimezoneDataType,
21
- entries: AssessmentResult::EntryArray,
22
- exclude_controls: AssessmentResult::ExcludeControlArray,
23
- exclude_objectives: AssessmentResult::ExcludeObjectiveArray,
24
- expires: DateTimeWithTimezoneDataType,
25
- findings: AssessmentResult::FindingArray,
26
- href: UriReference,
27
- implementation_statement_uuid: Uuid,
28
- import_ap: AssessmentResult::ImportAP,
29
- import_ssp: AssessmentPlan::ImportSSP,
30
- include_all: AssessmentResult::IncludeAll,
31
- include_controls: AssessmentResult::IncludeControlArray,
32
- inventory_items: AssessmentResult::InventoryItemArray,
33
- links: AssessmentResult::LinkArray,
34
- local_definitions: AssessmentResult::LocalDefinitions,
35
- metadata: MetadataBlockWrapper,
36
- methods: AssessmentResult::MethodArray,
37
- objective_id: TokenDataType,
38
- objectives_and_methods: AssessmentResult::ObjectivesAndMethodsArray,
39
- observations: AssessmentResult::ObservationArray,
40
- observation_uuid: Uuid,
41
- parts: AssessmentResult::PartArray,
42
- party_uuids: AssessmentResult::PartyUuidArray,
43
- props: AssessmentResult::PropArray,
44
- reason: TokenDataType,
45
- related_controls: AssessmentResult::RelatedControls,
46
- related_observations: AssessmentResult::RelatedObservationArray,
47
- related_risks: AssessmentResult::RelatedRiskArray,
48
- remarks: MarkupMultilineDataType,
49
- responsible_roles: AssessmentResult::ResponsibleRoleArray,
50
- results: AssessmentResult::ResultArray,
51
- reviewed_controls: AssessmentResult::ReviewedControls,
52
- risks: AssessmentResult::RiskArray,
53
- risk_uuid: Uuid,
54
- role_id: TokenDataType,
55
- start: DateTimeWithTimezoneDataType,
56
- state: TokenDataType,
57
- status: AssessmentResult::Status,
58
- statement: MarkupMultilineDataType,
59
- statement_ids: AssessmentResult::StatementIdArray,
60
- steps: AssessmentResult::StepArray,
61
- subjects: AssessmentResult::SubjectArray,
62
- subject_uuid: Uuid,
63
- target: AssessmentResult::Target,
64
- target_id: TokenDataType,
65
- tasks: AssessmentResult::AssessmentTaskArray,
66
- title: MarkupMultilineDataType,
67
- type: TokenDataType,
68
- types: AssessmentResult::TypeArray,
69
- uuid: Uuid,
70
- users: AssessmentResult::UserArray,
71
- }.freeze
72
-
73
- def self.get_type_of_attribute(attribute_name)
74
- klass = Oscal::ATTRIBUTE_TYPE_HASH[attribute_name.to_sym]
75
- if klass == nil
76
- raise InvalidTypeError, "No type found for #{attribute_name}"
77
- else
78
- klass
79
- end
80
- end
81
- end
@@ -1,20 +0,0 @@
1
- require_relative "base_class"
2
-
3
- module Oscal
4
- class BackMatter < Oscal::BaseClass
5
- KEY = %i(resources)
6
-
7
- attr_accessor *KEY
8
-
9
- attr_serializable *KEY
10
-
11
- def set_value(key_name, val)
12
- case key_name
13
- when "resources"
14
- Resource.wrap(val)
15
- else
16
- val
17
- end
18
- end
19
- end
20
- end
@@ -1,11 +0,0 @@
1
- require_relative "base_class"
2
-
3
- module Oscal
4
- class Base64Object < Oscal::BaseClass
5
- KEY = %i(filename media_type value)
6
-
7
- attr_accessor *KEY
8
-
9
- attr_serializable *KEY
10
- end
11
- end
@@ -1,50 +0,0 @@
1
- require_relative "serializer"
2
-
3
- module Oscal
4
- class BaseClass
5
- include Serializer
6
-
7
- KEY = %i(val)
8
-
9
- attr_accessor *KEY
10
-
11
- attr_serializable *KEY
12
-
13
- def self.wrap(obj)
14
- klass = self
15
- return obj if obj.is_a? klass
16
- return klass.new(obj) unless obj.is_a? Array
17
-
18
- obj.map do |x|
19
- klass.wrap(x)
20
- end
21
- end
22
-
23
- def initialize(options = {})
24
- klass = self.class
25
-
26
- unless options.is_a? Hash
27
- options = { klass::KEY.first.to_s => options }
28
- end
29
-
30
- options.each_pair.each do |key, val|
31
- key_name = key.gsub("-", "_")
32
- key_name = "klass" if key == "class"
33
-
34
- unless klass::KEY.include?(key_name.to_sym)
35
- raise UnknownAttributeError.new(
36
- "Unknown key `#{key}` in #{klass.name}",
37
- )
38
- end
39
-
40
- val = set_value(key_name, val)
41
-
42
- send("#{key_name}=", val)
43
- end
44
- end
45
-
46
- def set_value(_key_name, val)
47
- val
48
- end
49
- end
50
- end
data/lib/oscal/catalog.rb DELETED
@@ -1,63 +0,0 @@
1
- require "date"
2
- require_relative "serializer"
3
- require_relative "common_utils"
4
-
5
- module Oscal
6
- class Catalog
7
- include Serializer
8
- include CommonUtils
9
-
10
- KEY = %i(uuid metadata params controls groups back_matter)
11
- attr_accessor *KEY
12
-
13
- attr_serializable *KEY
14
-
15
- def initialize(uuid, metadata, params, controls, groups, back_matter)
16
- @uuid = uuid
17
- @metadata = MetadataBlock.new(metadata)
18
- @params = Parameter.wrap(params) if params
19
- @controls = Control.wrap(controls) if controls
20
- @groups = Group.wrap(groups) if groups
21
- @back_matter = BackMatter.wrap(back_matter) if back_matter
22
-
23
- @all_controls = []
24
- end
25
-
26
- def self.load_from_yaml(path)
27
- yaml_data = safe_load_yaml(path)
28
- yaml_catalog = yaml_data["catalog"]
29
-
30
- uuid = yaml_catalog["uuid"]
31
- metadata = yaml_catalog["metadata"]
32
- params = yaml_catalog["params"]
33
- controls = yaml_catalog["controls"]
34
- groups = yaml_catalog["groups"]
35
- back_matter = yaml_catalog["back-matter"]
36
-
37
- Catalog.new(uuid, metadata, params, controls, groups, back_matter)
38
- end
39
-
40
- def get_all_controls
41
- append_all_control_group(self)
42
- @all_controls.uniq
43
- end
44
-
45
- def append_all_control_group(obj)
46
- if /Oscal::Control/.match?(obj.to_s)
47
- @all_controls << obj
48
- end
49
-
50
- if obj.respond_to?(:controls) && !obj.controls.nil?
51
- obj.controls.each do |c|
52
- append_all_control_group(c)
53
- end
54
- end
55
-
56
- if obj.respond_to?(:groups) && !obj.groups.nil?
57
- obj.groups.each do |g|
58
- append_all_control_group(g)
59
- end
60
- end
61
- end
62
- end
63
- end
data/lib/oscal/choice.rb DELETED
@@ -1,11 +0,0 @@
1
- require_relative "base_class"
2
-
3
- module Oscal
4
- class Choice < Oscal::BaseClass
5
- KEY = %i(val)
6
-
7
- attr_accessor *KEY
8
-
9
- attr_serializable *KEY
10
- end
11
- end
@@ -1,22 +0,0 @@
1
- require_relative "base_class"
2
-
3
- module Oscal
4
- class Citation < Oscal::BaseClass
5
- KEY = %i(text props links)
6
-
7
- attr_accessor *KEY
8
-
9
- attr_serializable *KEY
10
-
11
- def set_value(key_name, val)
12
- case key_name
13
- when "props"
14
- Property.wrap(val)
15
- when "links"
16
- Link.wrap(val)
17
- else
18
- val
19
- end
20
- end
21
- end
22
- end
data/lib/oscal/combine.rb DELETED
@@ -1,11 +0,0 @@
1
- require_relative "base_class"
2
-
3
- module Oscal
4
- class Combine < Oscal::BaseClass
5
- KEY = %i(method)
6
-
7
- attr_accessor *KEY
8
-
9
- attr_serializable *KEY
10
- end
11
- end
@@ -1,35 +0,0 @@
1
- module Oscal
2
- module CommonUtils
3
- def find_object_by_id(id, obj = self, attribute_name = :id)
4
- if obj.respond_to?(attribute_name) && obj.send(attribute_name) == id
5
- return obj
6
- end
7
-
8
- res = nil
9
-
10
- obj.instance_variables.each do |ins_var|
11
- val = obj.send(ins_var.to_s.delete("@").to_sym)
12
-
13
- if val.is_a? Array
14
- val.each do |v|
15
- res = find_object_by_id(id, v, attribute_name.to_sym)
16
- break unless res.nil?
17
- end
18
- else
19
- res = find_object_by_id(id, val, attribute_name.to_sym)
20
- end
21
-
22
- break unless res.nil?
23
- end
24
-
25
- res
26
- end
27
-
28
- def self.included(klass)
29
- klass.extend(ClassMethods)
30
- end
31
-
32
- module ClassMethods
33
- end
34
- end
35
- end