abide_dev_utils 0.10.1 → 0.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +7 -1
- data/Gemfile.lock +25 -19
- data/Rakefile +28 -0
- data/abide_dev_utils.gemspec +1 -0
- data/lib/abide_dev_utils/cem/benchmark.rb +490 -0
- data/lib/abide_dev_utils/cem/generate/coverage_report.rb +380 -0
- data/lib/abide_dev_utils/cem/generate/reference.rb +319 -0
- data/lib/abide_dev_utils/cem/generate.rb +11 -0
- data/lib/abide_dev_utils/cem/hiera_data/mapping_data/map_data.rb +110 -0
- data/lib/abide_dev_utils/cem/hiera_data/mapping_data/mixins.rb +46 -0
- data/lib/abide_dev_utils/cem/hiera_data/mapping_data.rb +146 -0
- data/lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb +127 -0
- data/lib/abide_dev_utils/cem/hiera_data/resource_data/parameters.rb +90 -0
- data/lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb +102 -0
- data/lib/abide_dev_utils/cem/hiera_data/resource_data.rb +310 -0
- data/lib/abide_dev_utils/cem/hiera_data.rb +7 -0
- data/lib/abide_dev_utils/cem/mapping/mapper.rb +282 -0
- data/lib/abide_dev_utils/cem/validate/resource_data.rb +33 -0
- data/lib/abide_dev_utils/cem/validate.rb +10 -0
- data/lib/abide_dev_utils/cem.rb +1 -0
- data/lib/abide_dev_utils/cli/cem.rb +98 -0
- data/lib/abide_dev_utils/dot_number_comparable.rb +75 -0
- data/lib/abide_dev_utils/errors/cem.rb +32 -0
- data/lib/abide_dev_utils/errors/general.rb +8 -2
- data/lib/abide_dev_utils/errors/ppt.rb +4 -0
- data/lib/abide_dev_utils/errors.rb +6 -0
- data/lib/abide_dev_utils/markdown.rb +104 -0
- data/lib/abide_dev_utils/ppt/class_utils.rb +1 -1
- data/lib/abide_dev_utils/ppt/code_gen/data_types.rb +64 -0
- data/lib/abide_dev_utils/ppt/code_gen/generate.rb +15 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource.rb +59 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb +93 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types/class.rb +17 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types/manifest.rb +16 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types/parameter.rb +16 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types/strings.rb +13 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types.rb +6 -0
- data/lib/abide_dev_utils/ppt/code_gen.rb +15 -0
- data/lib/abide_dev_utils/ppt/code_introspection.rb +102 -0
- data/lib/abide_dev_utils/ppt/facter_utils.rb +140 -0
- data/lib/abide_dev_utils/ppt/hiera.rb +300 -0
- data/lib/abide_dev_utils/ppt/puppet_module.rb +75 -0
- data/lib/abide_dev_utils/ppt.rb +6 -5
- data/lib/abide_dev_utils/validate.rb +14 -0
- data/lib/abide_dev_utils/version.rb +1 -1
- data/lib/abide_dev_utils/xccdf/parser/helpers.rb +146 -0
- data/lib/abide_dev_utils/xccdf/parser/objects.rb +87 -144
- data/lib/abide_dev_utils/xccdf/parser.rb +5 -0
- data/lib/abide_dev_utils/xccdf/utils.rb +89 -0
- data/lib/abide_dev_utils/xccdf.rb +3 -0
- metadata +50 -3
- data/lib/abide_dev_utils/ppt/coverage.rb +0 -86
@@ -0,0 +1,146 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AbideDevUtils
|
4
|
+
module XCCDF
|
5
|
+
module Parser
|
6
|
+
module Helpers
|
7
|
+
# Provides helper methods for working with XCCDF element children
|
8
|
+
module ElementChildren
|
9
|
+
def search_children
|
10
|
+
@search_children ||= SearchChildren.new(children)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Implements methods that allow for searching an XCCDF Element's children
|
14
|
+
class SearchChildren
|
15
|
+
attr_reader :children
|
16
|
+
|
17
|
+
def initialize(children)
|
18
|
+
@children = children
|
19
|
+
end
|
20
|
+
|
21
|
+
def recursive_select_children(children_to_search = children, &block)
|
22
|
+
search_hits = []
|
23
|
+
children_to_search.each do |child|
|
24
|
+
found = yield child
|
25
|
+
if found
|
26
|
+
search_hits << child
|
27
|
+
elsif child.respond_to?(:children)
|
28
|
+
search_hits << recursive_select_children(child.children, &block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
search_hits.flatten.compact.uniq
|
32
|
+
end
|
33
|
+
|
34
|
+
def recursive_find_child(children_to_search = children, &block)
|
35
|
+
rescursive_select_children(children_to_search, &block).first
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_children_that_respond_to(method, recurse: false)
|
39
|
+
return recursive_select_children { |child| child.respond_to?(method) } if recurse
|
40
|
+
|
41
|
+
children.select { |c| c.respond_to?(method.to_sym) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_children_by_class(klass, recurse: false)
|
45
|
+
return recursive_select_children { |child| child.instance_of?(klass) } if recurse
|
46
|
+
|
47
|
+
children.select { |child| child.instance_of?(klass) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_child_by_class(klass, recurse: false)
|
51
|
+
return recursive_find_child { |child| child.is_a?(klass) } if recurse
|
52
|
+
|
53
|
+
find_children_by_class(klass).first
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_children_by_xpath(xpath, recurse: false)
|
57
|
+
return recursive_select_children { |child| child.xpath == xpath } if recurse
|
58
|
+
|
59
|
+
children.select { |child| child.xpath == xpath }
|
60
|
+
end
|
61
|
+
|
62
|
+
def find_child_by_xpath(xpath, recurse: false)
|
63
|
+
return recursive_find_child { |child| child.xpath == xpath } if recurse
|
64
|
+
|
65
|
+
find_children_by_xpath(xpath).first
|
66
|
+
end
|
67
|
+
|
68
|
+
def find_children_by_attribute(attribute, recurse: false)
|
69
|
+
pr = proc do |child|
|
70
|
+
next unless child.instance_of?(AbideDevUtils::XCCDF::Parser::Objects::AttributeValue)
|
71
|
+
|
72
|
+
child.attribute == attribute
|
73
|
+
end
|
74
|
+
return recursive_select_children(&pr) if recurse
|
75
|
+
|
76
|
+
children.select(&pr)
|
77
|
+
end
|
78
|
+
|
79
|
+
def find_child_by_attribute(attribute, recurse: false)
|
80
|
+
find_children_by_attribute(attribute, recurse: recurse).first
|
81
|
+
end
|
82
|
+
|
83
|
+
def find_children_by_attribute_value(attribute, value, recurse: false)
|
84
|
+
pr = proc do |child|
|
85
|
+
next unless child.instance_of?(AbideDevUtils::XCCDF::Parser::Objects::AttributeValue)
|
86
|
+
|
87
|
+
child.attribute == attribute && child.value == value
|
88
|
+
end
|
89
|
+
return recursive_select_children(&pr) if recurse
|
90
|
+
|
91
|
+
children.select(&pr)
|
92
|
+
end
|
93
|
+
|
94
|
+
def find_child_by_attribute_value(attribute, value, recurse: false)
|
95
|
+
find_children_by_attribute_value(attribute, value, recurse: recurse).first
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Provides helper methods for working with XML xpaths
|
101
|
+
module XPath
|
102
|
+
def find_element
|
103
|
+
FindElement
|
104
|
+
end
|
105
|
+
|
106
|
+
# Implements class methods to help with finding elements via XPath
|
107
|
+
class FindElement
|
108
|
+
def self.xpath(element, path)
|
109
|
+
elem = namespace_safe_xpath(element, path)
|
110
|
+
return named_xpath(element, path) if elem.nil?
|
111
|
+
|
112
|
+
elem
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.at_xpath(element, path)
|
116
|
+
elem = namespace_safe_at_xpath(element, path)
|
117
|
+
return named_at_xpath(element, path) if elem.nil?
|
118
|
+
|
119
|
+
elem
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.namespace_safe_xpath(element, path)
|
123
|
+
element.xpath(path)
|
124
|
+
rescue Nokogiri::XML::XPath::SyntaxError
|
125
|
+
named_xpath(element, path)
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.namespace_safe_at_xpath(element, path)
|
129
|
+
element.at_xpath(path)
|
130
|
+
rescue Nokogiri::XML::XPath::SyntaxError
|
131
|
+
named_at_xpath(element, path)
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.named_xpath(element, path)
|
135
|
+
element.xpath("*[name()='#{path}']")
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.named_at_xpath(element, path)
|
139
|
+
element.at_xpath("*[name()='#{path}']")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'digest'
|
4
4
|
require_relative './objects/digest_object'
|
5
5
|
require_relative './objects/numbered_object'
|
6
|
+
require_relative './helpers'
|
6
7
|
|
7
8
|
module AbideDevUtils
|
8
9
|
module XCCDF
|
@@ -12,6 +13,9 @@ module AbideDevUtils
|
|
12
13
|
# Base class for XCCDF element objects
|
13
14
|
class ElementBase
|
14
15
|
include AbideDevUtils::XCCDF::Parser::Objects::DigestObject
|
16
|
+
include AbideDevUtils::XCCDF::Parser::Helpers::ElementChildren
|
17
|
+
include AbideDevUtils::XCCDF::Parser::Helpers::XPath
|
18
|
+
extend AbideDevUtils::XCCDF::Parser::Helpers::XPath
|
15
19
|
attr_reader :children, :child_labels, :link_labels
|
16
20
|
|
17
21
|
def initialize(*_args, **_kwargs)
|
@@ -25,12 +29,21 @@ module AbideDevUtils
|
|
25
29
|
|
26
30
|
# For subclasses that are associated with a specific
|
27
31
|
# XCCDF element, this method returns the element's
|
28
|
-
# xpath. Must be overridden by subclasses that
|
32
|
+
# xpath name. Must be overridden by subclasses that
|
29
33
|
# implement this method.
|
30
34
|
def self.xpath
|
31
35
|
nil
|
32
36
|
end
|
33
37
|
|
38
|
+
# For subclasses that are associated with a specific
|
39
|
+
# XCCDF element that has valid namespace prefix,
|
40
|
+
# this method returns that namespaces. May be
|
41
|
+
# overridden by subclasses if they have a different
|
42
|
+
# valid namespace prefix.
|
43
|
+
def self.xmlns
|
44
|
+
'xccdf'
|
45
|
+
end
|
46
|
+
|
34
47
|
# Takes the last segment of the class name, splits on captial letters,
|
35
48
|
# and returns a downcased string joined by dashes. This gives us the
|
36
49
|
# XCCDF element type. Example: 'AbideDevUtils::XCCDF::Parser::Objects::ComplexCheck'
|
@@ -66,6 +79,8 @@ module AbideDevUtils
|
|
66
79
|
found
|
67
80
|
end
|
68
81
|
@label_method_values[label_str]
|
82
|
+
elsif search_children.respond_to?(method_name)
|
83
|
+
search_children.send(method_name, *args, &block)
|
69
84
|
else
|
70
85
|
super
|
71
86
|
end
|
@@ -93,83 +108,6 @@ module AbideDevUtils
|
|
93
108
|
@label
|
94
109
|
end
|
95
110
|
|
96
|
-
def recursive_select_children(children_to_search = children, &block)
|
97
|
-
search_hits = []
|
98
|
-
children_to_search.each do |child|
|
99
|
-
found = yield child
|
100
|
-
if found
|
101
|
-
search_hits << child
|
102
|
-
elsif child.respond_to?(:children)
|
103
|
-
search_hits << recursive_select_children(child.children, &block)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
search_hits.flatten.compact.uniq
|
107
|
-
end
|
108
|
-
|
109
|
-
def recursive_find_child(children_to_search = children, &block)
|
110
|
-
rescursive_select_children(children_to_search, &block).first
|
111
|
-
end
|
112
|
-
|
113
|
-
def find_children_that_respond_to(method, recurse: false)
|
114
|
-
return recursive_select_children { |child| child.respond_to?(method) } if recurse
|
115
|
-
|
116
|
-
children.select { |c| c.respond_to?(method.to_sym) }
|
117
|
-
end
|
118
|
-
|
119
|
-
def find_children_by_class(klass, recurse: false)
|
120
|
-
return recursive_select_children { |child| child.instance_of?(klass) } if recurse
|
121
|
-
|
122
|
-
children.select { |child| child.instance_of?(klass) }
|
123
|
-
end
|
124
|
-
|
125
|
-
def find_child_by_class(klass, recurse: false)
|
126
|
-
return recursive_find_child { |child| child.is_a?(klass) } if recurse
|
127
|
-
|
128
|
-
find_children_by_class(klass).first
|
129
|
-
end
|
130
|
-
|
131
|
-
def find_children_by_xpath(xpath, recurse: false)
|
132
|
-
return recursive_select_children { |child| child.xpath == xpath } if recurse
|
133
|
-
|
134
|
-
children.select { |child| child.xpath == xpath }
|
135
|
-
end
|
136
|
-
|
137
|
-
def find_child_by_xpath(xpath, recurse: false)
|
138
|
-
return recursive_find_child { |child| child.xpath == xpath } if recurse
|
139
|
-
|
140
|
-
find_children_by_xpath(xpath).first
|
141
|
-
end
|
142
|
-
|
143
|
-
def find_children_by_attribute(attribute, recurse: false)
|
144
|
-
pr = proc do |child|
|
145
|
-
next unless child.instance_of?(AbideDevUtils::XCCDF::Parser::Objects::AttributeValue)
|
146
|
-
|
147
|
-
child.attribute == attribute
|
148
|
-
end
|
149
|
-
return recursive_select_children(&pr) if recurse
|
150
|
-
|
151
|
-
children.select(&pr)
|
152
|
-
end
|
153
|
-
|
154
|
-
def find_child_by_attribute(attribute, recurse: false)
|
155
|
-
find_children_by_attribute(attribute, recurse: recurse).first
|
156
|
-
end
|
157
|
-
|
158
|
-
def find_children_by_attribute_value(attribute, value, recurse: false)
|
159
|
-
pr = proc do |child|
|
160
|
-
next unless child.instance_of?(AbideDevUtils::XCCDF::Parser::Objects::AttributeValue)
|
161
|
-
|
162
|
-
child.attribute == attribute && child.value == value
|
163
|
-
end
|
164
|
-
return recursive_select_children(&pr) if recurse
|
165
|
-
|
166
|
-
children.select(&pr)
|
167
|
-
end
|
168
|
-
|
169
|
-
def find_child_by_attribute_value(attribute, value, recurse: false)
|
170
|
-
find_children_by_attribute_value(attribute, value, recurse: recurse).first
|
171
|
-
end
|
172
|
-
|
173
111
|
def add_link(object)
|
174
112
|
@links << object
|
175
113
|
@link_labels << object.label unless @link_labels.include?(object.label)
|
@@ -187,22 +125,10 @@ module AbideDevUtils
|
|
187
125
|
default
|
188
126
|
end
|
189
127
|
|
190
|
-
def namespace_safe_xpath(element, path)
|
191
|
-
element.xpath(path)
|
192
|
-
rescue Nokogiri::XML::XPath::SyntaxError
|
193
|
-
element.xpath("*[name()='#{path}']")
|
194
|
-
end
|
195
|
-
|
196
|
-
def namespace_safe_at_xpath(element, path)
|
197
|
-
element.at_xpath(path)
|
198
|
-
rescue Nokogiri::XML::XPath::SyntaxError
|
199
|
-
element.at_xpath("*[name()='#{path}']")
|
200
|
-
end
|
201
|
-
|
202
128
|
def add_child(klass, element, *args, **kwargs)
|
203
129
|
return if element.nil?
|
204
130
|
|
205
|
-
real_element = klass.xpath.nil? ? element :
|
131
|
+
real_element = klass.xpath.nil? ? element : find_element.at_xpath(element, klass.xpath)
|
206
132
|
return if real_element.nil?
|
207
133
|
|
208
134
|
obj = new_object(klass, real_element, *args, **kwargs)
|
@@ -219,7 +145,7 @@ module AbideDevUtils
|
|
219
145
|
def add_children(klass, element, *args, **kwargs)
|
220
146
|
return if element.nil?
|
221
147
|
|
222
|
-
real_elements = klass.xpath.nil? ? element :
|
148
|
+
real_elements = klass.xpath.nil? ? element : find_element.xpath(element, klass.xpath)
|
223
149
|
return if real_elements.nil?
|
224
150
|
|
225
151
|
real_elements.each do |e|
|
@@ -294,11 +220,11 @@ module AbideDevUtils
|
|
294
220
|
end
|
295
221
|
|
296
222
|
def self.xpath
|
297
|
-
'
|
223
|
+
'title'
|
298
224
|
end
|
299
225
|
|
300
226
|
def to_s
|
301
|
-
find_child_by_class(ShortText).to_s
|
227
|
+
search_children.find_child_by_class(ShortText).to_s
|
302
228
|
end
|
303
229
|
end
|
304
230
|
|
@@ -310,11 +236,11 @@ module AbideDevUtils
|
|
310
236
|
end
|
311
237
|
|
312
238
|
def self.xpath
|
313
|
-
'
|
239
|
+
'description'
|
314
240
|
end
|
315
241
|
|
316
242
|
def to_s
|
317
|
-
find_child_by_class(LongText).to_s
|
243
|
+
search_children.find_child_by_class(LongText).to_s
|
318
244
|
end
|
319
245
|
end
|
320
246
|
|
@@ -325,7 +251,7 @@ module AbideDevUtils
|
|
325
251
|
def initialize(element)
|
326
252
|
super
|
327
253
|
add_child(AttributeValue, element, 'id')
|
328
|
-
@id = find_child_by_attribute('id').value.to_s
|
254
|
+
@id = search_children.find_child_by_attribute('id').value.to_s
|
329
255
|
end
|
330
256
|
|
331
257
|
def to_s
|
@@ -340,7 +266,7 @@ module AbideDevUtils
|
|
340
266
|
def initialize(element)
|
341
267
|
super
|
342
268
|
add_child(AttributeValue, element, 'idref')
|
343
|
-
@idref = find_child_by_attribute('idref').value.to_s
|
269
|
+
@idref = search_children.find_child_by_attribute('idref').value.to_s
|
344
270
|
end
|
345
271
|
|
346
272
|
def to_s
|
@@ -356,7 +282,7 @@ module AbideDevUtils
|
|
356
282
|
end
|
357
283
|
|
358
284
|
def self.xpath
|
359
|
-
'
|
285
|
+
'select'
|
360
286
|
end
|
361
287
|
end
|
362
288
|
|
@@ -378,7 +304,7 @@ module AbideDevUtils
|
|
378
304
|
end
|
379
305
|
|
380
306
|
def self.xpath
|
381
|
-
'
|
307
|
+
'Profile'
|
382
308
|
end
|
383
309
|
end
|
384
310
|
|
@@ -389,7 +315,7 @@ module AbideDevUtils
|
|
389
315
|
|
390
316
|
def initialize(element)
|
391
317
|
super
|
392
|
-
@number = to_s[/group_([0-9]+\.)+[0-9]+|group_([0-9]+)/]
|
318
|
+
@number = to_s[/group_([0-9]+\.)+[0-9]+|group_([0-9]+)/]&.gsub(/group_/, '')
|
393
319
|
add_child(Title, element)
|
394
320
|
add_child(Description, element)
|
395
321
|
add_children(Group, element)
|
@@ -397,7 +323,7 @@ module AbideDevUtils
|
|
397
323
|
end
|
398
324
|
|
399
325
|
def self.xpath
|
400
|
-
'
|
326
|
+
'Group'
|
401
327
|
end
|
402
328
|
end
|
403
329
|
|
@@ -410,11 +336,11 @@ module AbideDevUtils
|
|
410
336
|
end
|
411
337
|
|
412
338
|
def self.xpath
|
413
|
-
'
|
339
|
+
'check-export'
|
414
340
|
end
|
415
341
|
|
416
342
|
def to_s
|
417
|
-
[find_child_by_attribute('export-name').to_s, find_child_by_attribute('value-id').to_s].join('|')
|
343
|
+
[search_children.find_child_by_attribute('export-name').to_s, search_children.find_child_by_attribute('value-id').to_s].join('|')
|
418
344
|
end
|
419
345
|
end
|
420
346
|
|
@@ -427,11 +353,11 @@ module AbideDevUtils
|
|
427
353
|
end
|
428
354
|
|
429
355
|
def self.xpath
|
430
|
-
'
|
356
|
+
'check-content-ref'
|
431
357
|
end
|
432
358
|
|
433
359
|
def to_s
|
434
|
-
[find_child_by_attribute('href').to_s, find_child_by_attribute('name').to_s].join('|')
|
360
|
+
[search_children.find_child_by_attribute('href').to_s, search_children.find_child_by_attribute('name').to_s].join('|')
|
435
361
|
end
|
436
362
|
end
|
437
363
|
|
@@ -445,7 +371,7 @@ module AbideDevUtils
|
|
445
371
|
end
|
446
372
|
|
447
373
|
def self.xpath
|
448
|
-
'
|
374
|
+
'check'
|
449
375
|
end
|
450
376
|
end
|
451
377
|
|
@@ -484,7 +410,7 @@ module AbideDevUtils
|
|
484
410
|
end
|
485
411
|
|
486
412
|
def self.xpath
|
487
|
-
'
|
413
|
+
'ident'
|
488
414
|
end
|
489
415
|
|
490
416
|
def to_s
|
@@ -503,7 +429,7 @@ module AbideDevUtils
|
|
503
429
|
end
|
504
430
|
|
505
431
|
def self.xpath
|
506
|
-
'
|
432
|
+
'complex-check'
|
507
433
|
end
|
508
434
|
end
|
509
435
|
|
@@ -514,18 +440,24 @@ module AbideDevUtils
|
|
514
440
|
add_child(ShortText, element['title'])
|
515
441
|
add_child(ShortText, element['urn'])
|
516
442
|
new_implementation_groups(element)
|
517
|
-
add_child(ShortText,
|
518
|
-
add_child(ShortText,
|
443
|
+
add_child(ShortText, find_element.at_xpath(element, 'asset_type').text)
|
444
|
+
add_child(ShortText, find_element.at_xpath(element, 'security_function').text)
|
519
445
|
end
|
520
446
|
|
521
447
|
def self.xpath
|
522
|
-
'
|
448
|
+
'safeguard'
|
449
|
+
end
|
450
|
+
|
451
|
+
def self.xmlns
|
452
|
+
'controls'
|
523
453
|
end
|
524
454
|
|
525
455
|
private
|
526
456
|
|
527
457
|
def new_implementation_groups(element)
|
528
|
-
igroup =
|
458
|
+
igroup = find_element.at_xpath(element, 'implementation_groups')
|
459
|
+
return if igroup.nil? || igroup.empty?
|
460
|
+
|
529
461
|
add_child(ShortText, igroup['ig1']) if igroup['ig1']
|
530
462
|
add_child(ShortText, igroup['ig2']) if igroup['ig2']
|
531
463
|
add_child(ShortText, igroup['ig3']) if igroup['ig3']
|
@@ -541,7 +473,11 @@ module AbideDevUtils
|
|
541
473
|
end
|
542
474
|
|
543
475
|
def self.xpath
|
544
|
-
'
|
476
|
+
'framework'
|
477
|
+
end
|
478
|
+
|
479
|
+
def self.xmlns
|
480
|
+
'controls'
|
545
481
|
end
|
546
482
|
end
|
547
483
|
|
@@ -549,15 +485,22 @@ module AbideDevUtils
|
|
549
485
|
class MetadataCisControls < ElementBase
|
550
486
|
def initialize(element, parent: nil)
|
551
487
|
super
|
552
|
-
add_child(AttributeValue, element, '
|
488
|
+
add_child(AttributeValue, element, 'controls')
|
553
489
|
add_children(MetadataCisControlsFramework, element)
|
554
490
|
end
|
555
491
|
|
556
492
|
def self.xpath
|
557
|
-
'
|
493
|
+
'cis_controls'
|
494
|
+
end
|
495
|
+
|
496
|
+
def self.xmlns
|
497
|
+
'controls'
|
558
498
|
end
|
559
499
|
end
|
560
500
|
|
501
|
+
# class MetadataNotes < ElementBase
|
502
|
+
# def initialize()
|
503
|
+
|
561
504
|
# Class for XCCDF rule metadata element
|
562
505
|
class Metadata < ElementBase
|
563
506
|
def initialize(element, parent: nil)
|
@@ -566,7 +509,7 @@ module AbideDevUtils
|
|
566
509
|
end
|
567
510
|
|
568
511
|
def self.xpath
|
569
|
-
'
|
512
|
+
'metadata'
|
570
513
|
end
|
571
514
|
end
|
572
515
|
|
@@ -582,7 +525,7 @@ module AbideDevUtils
|
|
582
525
|
end
|
583
526
|
|
584
527
|
def self.xpath
|
585
|
-
'
|
528
|
+
'rationale'
|
586
529
|
end
|
587
530
|
|
588
531
|
def to_s
|
@@ -598,15 +541,15 @@ module AbideDevUtils
|
|
598
541
|
end
|
599
542
|
|
600
543
|
def digest
|
601
|
-
@digest ||= find_child_by_class(LongText).digest
|
544
|
+
@digest ||= search_children.find_child_by_class(LongText).digest
|
602
545
|
end
|
603
546
|
|
604
547
|
def self.xpath
|
605
|
-
'
|
548
|
+
'fixtext'
|
606
549
|
end
|
607
550
|
|
608
551
|
def to_s
|
609
|
-
find_child_by_class(LongText).to_s
|
552
|
+
search_children.find_child_by_class(LongText).to_s
|
610
553
|
end
|
611
554
|
end
|
612
555
|
|
@@ -632,7 +575,7 @@ module AbideDevUtils
|
|
632
575
|
end
|
633
576
|
|
634
577
|
def self.xpath
|
635
|
-
'
|
578
|
+
'Rule'
|
636
579
|
end
|
637
580
|
end
|
638
581
|
|
@@ -644,15 +587,15 @@ module AbideDevUtils
|
|
644
587
|
add_child(AttributeValue, element, 'type')
|
645
588
|
add_child(Title, element)
|
646
589
|
add_child(Description, element)
|
647
|
-
add_child(ShortText,
|
590
|
+
add_child(ShortText, find_element.at_xpath(element, 'value'))
|
648
591
|
end
|
649
592
|
|
650
593
|
def self.xpath
|
651
|
-
'
|
594
|
+
'Value'
|
652
595
|
end
|
653
596
|
|
654
597
|
def to_s
|
655
|
-
find_child_by_class(Title).to_s
|
598
|
+
search_children.find_child_by_class(Title).to_s
|
656
599
|
end
|
657
600
|
end
|
658
601
|
|
@@ -665,13 +608,13 @@ module AbideDevUtils
|
|
665
608
|
end
|
666
609
|
|
667
610
|
def self.xpath
|
668
|
-
'
|
611
|
+
'status'
|
669
612
|
end
|
670
613
|
|
671
614
|
def to_s
|
672
615
|
[
|
673
|
-
"Status:#{find_child_by_class(ShortText)}",
|
674
|
-
"Date:#{find_child_by_class(AttributeValue)}",
|
616
|
+
"Status:#{search_children.find_child_by_class(ShortText)}",
|
617
|
+
"Date:#{search_children.find_child_by_class(AttributeValue)}",
|
675
618
|
].join('|')
|
676
619
|
end
|
677
620
|
end
|
@@ -684,11 +627,11 @@ module AbideDevUtils
|
|
684
627
|
end
|
685
628
|
|
686
629
|
def self.xpath
|
687
|
-
'
|
630
|
+
'version'
|
688
631
|
end
|
689
632
|
|
690
633
|
def to_s
|
691
|
-
find_child_by_class(ShortText).to_s
|
634
|
+
search_children.find_child_by_class(ShortText).to_s
|
692
635
|
end
|
693
636
|
end
|
694
637
|
|
@@ -700,11 +643,11 @@ module AbideDevUtils
|
|
700
643
|
end
|
701
644
|
|
702
645
|
def self.xpath
|
703
|
-
'
|
646
|
+
'platform'
|
704
647
|
end
|
705
648
|
|
706
649
|
def to_s
|
707
|
-
find_child_by_class(AttributeValue).to_s
|
650
|
+
search_children.find_child_by_class(AttributeValue).to_s
|
708
651
|
end
|
709
652
|
end
|
710
653
|
|
@@ -714,25 +657,25 @@ module AbideDevUtils
|
|
714
657
|
|
715
658
|
def initialize(element)
|
716
659
|
super
|
717
|
-
|
718
|
-
raise 'No Benchmark element found' if
|
660
|
+
elem = find_element.at_xpath(element, 'Benchmark')
|
661
|
+
raise 'No Benchmark element found' if elem.nil?
|
719
662
|
|
720
|
-
add_child(Status,
|
721
|
-
add_child(Title,
|
722
|
-
add_child(Description,
|
723
|
-
add_child(Platform,
|
724
|
-
add_child(Version,
|
725
|
-
add_children(Profile,
|
726
|
-
add_children(Group,
|
727
|
-
add_children(Value,
|
663
|
+
add_child(Status, elem)
|
664
|
+
add_child(Title, elem)
|
665
|
+
add_child(Description, elem)
|
666
|
+
add_child(Platform, elem)
|
667
|
+
add_child(Version, elem)
|
668
|
+
add_children(Profile, elem)
|
669
|
+
add_children(Group, elem)
|
670
|
+
add_children(Value, elem)
|
728
671
|
end
|
729
672
|
|
730
673
|
def self.xpath
|
731
|
-
'
|
674
|
+
'Benchmark'
|
732
675
|
end
|
733
676
|
|
734
677
|
def to_s
|
735
|
-
[find_child_by_class(Title).to_s, find_child_by_class(Version).to_s].join(' ')
|
678
|
+
[search_children.find_child_by_class(Title).to_s, search_children.find_child_by_class(Version).to_s].join(' ')
|
736
679
|
end
|
737
680
|
end
|
738
681
|
end
|
@@ -9,6 +9,7 @@ module AbideDevUtils
|
|
9
9
|
module Parser
|
10
10
|
def self.parse(file_path)
|
11
11
|
doc = AbideDevUtils::Files::Reader.read(file_path)
|
12
|
+
doc.remove_namespaces!
|
12
13
|
benchmark = AbideDevUtils::XCCDF::Parser::Objects::Benchmark.new(doc)
|
13
14
|
Linker.resolve_links(benchmark)
|
14
15
|
benchmark
|
@@ -24,6 +25,8 @@ module AbideDevUtils
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def self.link_profile_rules(benchmark)
|
28
|
+
return unless benchmark.respond_to?(:profile)
|
29
|
+
|
27
30
|
rules = benchmark.find_children_by_class(AbideDevUtils::XCCDF::Parser::Objects::Rule, recurse: true)
|
28
31
|
benchmark.profile.each do |profile|
|
29
32
|
profile.xccdf_select.each do |sel|
|
@@ -36,6 +39,8 @@ module AbideDevUtils
|
|
36
39
|
end
|
37
40
|
|
38
41
|
def self.link_rule_values(benchmark)
|
42
|
+
return unless benchmark.respond_to?(:value)
|
43
|
+
|
39
44
|
rules = benchmark.find_children_by_class(AbideDevUtils::XCCDF::Parser::Objects::Rule, recurse: true)
|
40
45
|
benchmark.value.each do |value|
|
41
46
|
rules.each do |rule|
|