abide_dev_utils 0.9.5 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 711f2a50975733ef2c8dc08eefc93ec22e7470c495b450063bdff4860b55246e
4
- data.tar.gz: f5a56c3f41894ee32a141d600d4a97a46f673922786941901f6afb55c841dfd1
3
+ metadata.gz: c47baf812f2bb3b64951dc87b3aa1886eca947f0bf3a57bbed12b7ed7fda97ab
4
+ data.tar.gz: 4488f609550b251474337f1574c5c216601035fc5bba1fc9acb76e278252b5b5
5
5
  SHA512:
6
- metadata.gz: efe26fa96de31974f97fa6677196cf68bb1961391cd9ce9cad153ce77f4b0222da47dad6a7dabd3ed18d8ec5f48b0b12d6c9521fae54d80820240f8418a31b36
7
- data.tar.gz: 2357180ce57243d105361bd3eb5d5a5458e319369014b4193991fea33746e303c75a85a51812501d2b23fdfde11912ab9b3aded0e7135ba53071b9532b615379
6
+ metadata.gz: f4e517c44f1c728689d1de11d0e306f65352ecf1b0507671d588ac5eb21dc294ac7bca68e7c790f21b9a47fa565ed775c2a28ce45257395203a0fa296c6f4389
7
+ data.tar.gz: 2b5ff4f1ad40d4000bb93862902c1a89e4620632825d19a34cd118fa43cc15823132cb4e9d246a1655ad1f6bd9636581398651e9082e8b16129f0c79eba9a5df
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abide_dev_utils (0.9.3)
4
+ abide_dev_utils (0.10.1)
5
+ amatch (~> 0.4)
5
6
  cmdparse (~> 3.0)
6
7
  google-cloud-storage (~> 1.34)
7
8
  hashdiff (~> 1.0)
8
- jira-ruby (~> 2.1)
9
- nokogiri (~> 1.11)
9
+ jira-ruby (~> 2.2)
10
+ nokogiri (~> 1.13)
10
11
  puppet (>= 6.23)
11
12
  ruby-progressbar (~> 1.11)
12
13
  selenium-webdriver (~> 4.0.0.beta4)
@@ -14,73 +15,59 @@ PATH
14
15
  GEM
15
16
  remote: https://rubygems.org/
16
17
  specs:
17
- activesupport (7.0.1)
18
+ CFPropertyList (2.3.6)
19
+ activesupport (7.0.3)
18
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
21
  i18n (>= 1.6, < 2)
20
22
  minitest (>= 5.1)
21
23
  tzinfo (~> 2.0)
22
24
  addressable (2.8.0)
23
25
  public_suffix (>= 2.0.2, < 5.0)
26
+ amatch (0.4.1)
27
+ mize
28
+ tins (~> 1.0)
24
29
  ast (2.4.2)
25
- async (1.30.1)
30
+ async (1.30.2)
26
31
  console (~> 1.10)
27
32
  nio4r (~> 2.3)
28
33
  timers (~> 4.1)
29
- async-http (0.56.5)
34
+ async-http (0.56.6)
30
35
  async (>= 1.25)
31
36
  async-io (>= 1.28)
32
37
  async-pool (>= 0.2)
33
38
  protocol-http (~> 0.22.0)
34
39
  protocol-http1 (~> 0.14.0)
35
40
  protocol-http2 (~> 0.14.0)
41
+ traces (~> 0.4.0)
36
42
  async-http-faraday (0.11.0)
37
43
  async-http (~> 0.42)
38
44
  faraday
39
- async-io (1.32.2)
45
+ async-io (1.33.0)
40
46
  async
41
- async-pool (0.3.9)
47
+ async-pool (0.3.10)
42
48
  async (>= 1.25)
43
49
  atlassian-jwt (0.2.1)
44
50
  jwt (~> 2.1)
45
51
  childprocess (4.1.0)
46
52
  cmdparse (3.0.7)
47
53
  coderay (1.1.3)
48
- concurrent-ruby (1.1.9)
49
- console (1.14.0)
54
+ concurrent-ruby (1.1.10)
55
+ console (1.15.3)
50
56
  fiber-local
51
57
  declarative (0.0.20)
52
58
  deep_merge (1.2.2)
53
59
  diff-lcs (1.5.0)
54
60
  digest-crc (0.6.4)
55
61
  rake (>= 12.0.0, < 14.0.0)
56
- facter (4.2.7)
62
+ facter (4.2.10)
57
63
  hocon (~> 1.3)
58
64
  thor (>= 1.0.1, < 2.0)
59
- faraday (1.9.3)
60
- faraday-em_http (~> 1.0)
61
- faraday-em_synchrony (~> 1.0)
62
- faraday-excon (~> 1.1)
63
- faraday-httpclient (~> 1.0)
64
- faraday-multipart (~> 1.0)
65
- faraday-net_http (~> 1.0)
66
- faraday-net_http_persistent (~> 1.0)
67
- faraday-patron (~> 1.0)
68
- faraday-rack (~> 1.0)
69
- faraday-retry (~> 1.0)
65
+ faraday (2.3.0)
66
+ faraday-net_http (~> 2.0)
70
67
  ruby2_keywords (>= 0.0.4)
71
- faraday-em_http (1.0.0)
72
- faraday-em_synchrony (1.0.0)
73
- faraday-excon (1.1.0)
74
- faraday-http-cache (2.2.0)
68
+ faraday-http-cache (2.3.0)
75
69
  faraday (>= 0.8)
76
- faraday-httpclient (1.0.1)
77
- faraday-multipart (1.0.3)
78
- multipart-post (>= 1.2, < 3)
79
- faraday-net_http (1.0.1)
80
- faraday-net_http_persistent (1.2.0)
81
- faraday-patron (1.0.0)
82
- faraday-rack (1.0.0)
83
- faraday-retry (1.0.3)
70
+ faraday-net_http (2.0.3)
84
71
  fast_gettext (1.8.0)
85
72
  fiber-local (1.0.0)
86
73
  gem-release (2.2.2)
@@ -93,7 +80,7 @@ GEM
93
80
  octokit (~> 4.6)
94
81
  rainbow (>= 2.2.1)
95
82
  rake (>= 10.0)
96
- google-apis-core (0.4.1)
83
+ google-apis-core (0.5.0)
97
84
  addressable (~> 2.5, >= 2.5.1)
98
85
  googleauth (>= 0.16.2, < 2.a)
99
86
  httpclient (>= 2.8.1, < 3.a)
@@ -104,15 +91,15 @@ GEM
104
91
  webrick
105
92
  google-apis-iamcredentials_v1 (0.10.0)
106
93
  google-apis-core (>= 0.4, < 2.a)
107
- google-apis-storage_v1 (0.11.0)
94
+ google-apis-storage_v1 (0.14.0)
108
95
  google-apis-core (>= 0.4, < 2.a)
109
96
  google-cloud-core (1.6.0)
110
97
  google-cloud-env (~> 1.0)
111
98
  google-cloud-errors (~> 1.0)
112
- google-cloud-env (1.5.0)
113
- faraday (>= 0.17.3, < 2.0)
99
+ google-cloud-env (1.6.0)
100
+ faraday (>= 0.17.3, < 3.0)
114
101
  google-cloud-errors (1.2.0)
115
- google-cloud-storage (1.36.0)
102
+ google-cloud-storage (1.36.2)
116
103
  addressable (~> 2.8)
117
104
  digest-crc (~> 0.4)
118
105
  google-apis-iamcredentials_v1 (~> 0.1)
@@ -120,18 +107,18 @@ GEM
120
107
  google-cloud-core (~> 1.6)
121
108
  googleauth (>= 0.16.2, < 2.a)
122
109
  mini_mime (~> 1.0)
123
- googleauth (1.1.0)
124
- faraday (>= 0.17.3, < 2.0)
110
+ googleauth (1.1.3)
111
+ faraday (>= 0.17.3, < 3.a)
125
112
  jwt (>= 1.4, < 3.0)
126
113
  memoist (~> 0.16)
127
114
  multi_json (~> 1.11)
128
115
  os (>= 0.9, < 2.0)
129
116
  signet (>= 0.16, < 2.a)
130
117
  hashdiff (1.0.1)
131
- hiera (3.8.0)
118
+ hiera (3.9.0)
132
119
  hocon (1.3.1)
133
120
  httpclient (2.8.3)
134
- i18n (1.8.11)
121
+ i18n (1.10.0)
135
122
  concurrent-ruby (~> 1.0)
136
123
  jira-ruby (2.2.0)
137
124
  activesupport
@@ -143,25 +130,27 @@ GEM
143
130
  memoist (0.16.2)
144
131
  method_source (1.0.0)
145
132
  mini_mime (1.1.2)
146
- mini_portile2 (2.7.1)
147
133
  minitest (5.15.0)
134
+ mize (0.4.0)
135
+ protocol (~> 2.0)
148
136
  multi_json (1.15.0)
149
137
  multipart-post (2.1.1)
150
138
  nio4r (2.5.8)
151
- nokogiri (1.13.1)
152
- mini_portile2 (~> 2.7.0)
139
+ nokogiri (1.13.6-x86_64-darwin)
153
140
  racc (~> 1.4)
154
- oauth (0.5.8)
155
- octokit (4.22.0)
156
- faraday (>= 0.9)
157
- sawyer (~> 0.8.0, >= 0.5.3)
141
+ oauth (0.5.10)
142
+ octokit (4.23.0)
143
+ faraday (>= 1, < 3)
144
+ sawyer (~> 0.9)
158
145
  os (1.1.4)
159
- parallel (1.21.0)
160
- parser (3.1.0.0)
146
+ parallel (1.22.1)
147
+ parser (3.1.2.0)
161
148
  ast (~> 2.4.1)
149
+ protocol (2.0.0)
150
+ ruby_parser (~> 3.0)
162
151
  protocol-hpack (1.4.2)
163
- protocol-http (0.22.5)
164
- protocol-http1 (0.14.2)
152
+ protocol-http (0.22.6)
153
+ protocol-http1 (0.14.4)
165
154
  protocol-http (~> 0.22)
166
155
  protocol-http2 (0.14.2)
167
156
  protocol-hpack (~> 1.4)
@@ -169,8 +158,9 @@ GEM
169
158
  pry (0.14.1)
170
159
  coderay (~> 1.1)
171
160
  method_source (~> 1.0)
172
- public_suffix (4.0.6)
173
- puppet (7.13.1)
161
+ public_suffix (4.0.7)
162
+ puppet (7.17.0-universal-darwin)
163
+ CFPropertyList (~> 2.2)
174
164
  concurrent-ruby (~> 1.0)
175
165
  deep_merge (~> 1.0)
176
166
  facter (> 2.0.1, < 5)
@@ -186,63 +176,70 @@ GEM
186
176
  racc (1.6.0)
187
177
  rainbow (3.1.1)
188
178
  rake (13.0.6)
189
- regexp_parser (2.2.0)
190
- representable (3.1.1)
179
+ regexp_parser (2.5.0)
180
+ representable (3.2.0)
191
181
  declarative (< 0.1.0)
192
182
  trailblazer-option (>= 0.1.1, < 0.2.0)
193
183
  uber (< 0.2.0)
194
184
  retriable (3.1.2)
195
185
  rexml (3.2.5)
196
- rspec (3.10.0)
197
- rspec-core (~> 3.10.0)
198
- rspec-expectations (~> 3.10.0)
199
- rspec-mocks (~> 3.10.0)
200
- rspec-core (3.10.1)
201
- rspec-support (~> 3.10.0)
202
- rspec-expectations (3.10.2)
186
+ rspec (3.11.0)
187
+ rspec-core (~> 3.11.0)
188
+ rspec-expectations (~> 3.11.0)
189
+ rspec-mocks (~> 3.11.0)
190
+ rspec-core (3.11.0)
191
+ rspec-support (~> 3.11.0)
192
+ rspec-expectations (3.11.0)
203
193
  diff-lcs (>= 1.2.0, < 2.0)
204
- rspec-support (~> 3.10.0)
205
- rspec-mocks (3.10.2)
194
+ rspec-support (~> 3.11.0)
195
+ rspec-mocks (3.11.1)
206
196
  diff-lcs (>= 1.2.0, < 2.0)
207
- rspec-support (~> 3.10.0)
208
- rspec-support (3.10.3)
209
- rubocop (1.24.1)
197
+ rspec-support (~> 3.11.0)
198
+ rspec-support (3.11.0)
199
+ rubocop (1.30.0)
210
200
  parallel (~> 1.10)
211
- parser (>= 3.0.0.0)
201
+ parser (>= 3.1.0.0)
212
202
  rainbow (>= 2.2.2, < 4.0)
213
203
  regexp_parser (>= 1.8, < 3.0)
214
- rexml
215
- rubocop-ast (>= 1.15.1, < 2.0)
204
+ rexml (>= 3.2.5, < 4.0)
205
+ rubocop-ast (>= 1.18.0, < 2.0)
216
206
  ruby-progressbar (~> 1.7)
217
207
  unicode-display_width (>= 1.4.0, < 3.0)
218
- rubocop-ast (1.15.1)
219
- parser (>= 3.0.1.1)
208
+ rubocop-ast (1.18.0)
209
+ parser (>= 3.1.1.0)
220
210
  rubocop-i18n (3.0.0)
221
211
  rubocop (~> 1.0)
222
- rubocop-performance (1.13.1)
212
+ rubocop-performance (1.14.0)
223
213
  rubocop (>= 1.7.0, < 2.0)
224
214
  rubocop-ast (>= 0.4.0)
225
- rubocop-rspec (2.7.0)
215
+ rubocop-rspec (2.11.1)
226
216
  rubocop (~> 1.19)
227
217
  ruby-progressbar (1.11.0)
228
218
  ruby2_keywords (0.0.5)
219
+ ruby_parser (3.19.1)
220
+ sexp_processor (~> 4.16)
229
221
  rubyzip (2.3.2)
230
- sawyer (0.8.2)
222
+ sawyer (0.9.1)
231
223
  addressable (>= 2.3.5)
232
- faraday (> 0.8, < 2.0)
224
+ faraday (>= 0.17.3, < 3)
233
225
  scanf (1.0.0)
234
226
  selenium-webdriver (4.0.3)
235
227
  childprocess (>= 0.5, < 5.0)
236
228
  rexml (~> 3.2, >= 3.2.5)
237
229
  rubyzip (>= 1.2.2)
238
230
  semantic_puppet (1.0.4)
239
- signet (0.16.0)
231
+ sexp_processor (4.16.1)
232
+ signet (0.16.1)
240
233
  addressable (~> 2.8)
241
- faraday (>= 0.17.3, < 2.0)
234
+ faraday (>= 0.17.5, < 3.0)
242
235
  jwt (>= 1.5, < 3.0)
243
236
  multi_json (~> 1.10)
237
+ sync (0.5.0)
244
238
  thor (1.2.1)
245
239
  timers (4.3.3)
240
+ tins (1.31.1)
241
+ sync
242
+ traces (0.4.1)
246
243
  trailblazer-option (0.1.2)
247
244
  tzinfo (2.0.4)
248
245
  concurrent-ruby (~> 1.0)
@@ -251,7 +248,7 @@ GEM
251
248
  webrick (1.7.0)
252
249
 
253
250
  PLATFORMS
254
- ruby
251
+ x86_64-darwin-19
255
252
 
256
253
  DEPENDENCIES
257
254
  abide_dev_utils!
@@ -270,4 +267,4 @@ DEPENDENCIES
270
267
  rubocop-rspec (~> 2.1)
271
268
 
272
269
  BUNDLED WITH
273
- 2.1.4
270
+ 2.3.9
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ['lib']
33
33
 
34
34
  # Prod dependencies
35
- spec.add_dependency 'nokogiri', '~> 1.11'
35
+ spec.add_dependency 'nokogiri', '~> 1.13'
36
36
  spec.add_dependency 'cmdparse', '~> 3.0'
37
37
  spec.add_dependency 'puppet', '>= 6.23'
38
38
  spec.add_dependency 'jira-ruby', '~> 2.2'
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.add_dependency 'selenium-webdriver', '~> 4.0.0.beta4'
41
41
  spec.add_dependency 'google-cloud-storage', '~> 1.34'
42
42
  spec.add_dependency 'hashdiff', '~> 1.0'
43
+ spec.add_dependency 'amatch', '~> 0.4'
43
44
 
44
45
  # Dev dependencies
45
46
  spec.add_development_dependency 'bundler'
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'abide_dev_utils/xccdf'
4
+
5
+ module AbideDevUtils
6
+ # Methods for working with Compliance Enforcement Modules (CEM)
7
+ module CEM
8
+ def self.xccdf
9
+ return @xccdf if defined?(@xccdf)
10
+
11
+ xccdf = Object.new
12
+ xccdf.extend AbideDevUtils::XCCDF::Common
13
+ @xccdf = xccdf
14
+ @xccdf
15
+ end
16
+
17
+ def self.rule_id_format(rule_id)
18
+ case rule_id
19
+ when /^c[0-9_]+$/
20
+ :hiera_title_num
21
+ when /^[a-z][a-z0-9_]+$/
22
+ :hiera_title
23
+ when /^[0-9.]+$/
24
+ :number
25
+ else
26
+ :title
27
+ end
28
+ end
29
+
30
+ def self.rule_identifiers(rule_id)
31
+ {
32
+ number: xccdf.control_parts(rule_id).first,
33
+ hiera_title: xccdf.name_normalize_control(rule_id),
34
+ hiera_title_num: xccdf.number_normalize_control(rule_id),
35
+ }
36
+ end
37
+
38
+ def self.update_legacy_config_from_diff(config_hiera, diff)
39
+ new_config_hiera = config_hiera.dup
40
+ new_control_configs = {}
41
+ change_report = []
42
+ changes = diff.select { |d| d[:type][0] == :number }
43
+ config_hiera['config']['control_configs'].each do |key, val_hash|
44
+ key_id_format = rule_id_format(key)
45
+ changed = false
46
+ changes.each do |change|
47
+ if key_id_format == :title
48
+ next unless change[:title] == key
49
+ else
50
+ next unless rule_identifiers(change[:self].id)[key_id_format] == key
51
+ end
52
+
53
+ changed = true
54
+ new_key = if key_id_format == :title
55
+ change[:other_title]
56
+ else
57
+ rule_identifiers(change[:other].id)[key_id_format]
58
+ end
59
+ new_control_configs[new_key] = val_hash
60
+ change_report << {
61
+ type: :identifier_update,
62
+ from: key,
63
+ to: new_key,
64
+ }
65
+ end
66
+ new_control_configs[key] = val_hash unless changed
67
+ end
68
+ new_config_hiera['config']['control_configs'] = new_control_configs
69
+ [new_config_hiera, change_report]
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'abide_dev_utils/cem'
4
+ require 'abide_dev_utils/files'
5
+ require 'abide_dev_utils/output'
6
+ require 'abide_dev_utils/validate'
7
+ require 'abide_dev_utils/xccdf/diff/benchmark'
8
+ require 'abide_dev_utils/cli/abstract'
9
+
10
+ module Abide
11
+ module CLI
12
+ class CemCommand < AbideCommand
13
+ CMD_NAME = 'cem'
14
+ CMD_SHORT = 'Commands related to Puppet CEM'
15
+ CMD_LONG = 'Namespace for commands related to Puppet CEM'
16
+ def initialize
17
+ super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: true)
18
+ add_command(CemUpdateConfig.new)
19
+ end
20
+ end
21
+
22
+ class CemUpdateConfig < AbideCommand
23
+ CMD_NAME = 'update-config'
24
+ CMD_SHORT = 'Updates the Puppet CEM config'
25
+ CMD_LONG = 'Updates the Puppet CEM config'
26
+ def initialize
27
+ super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: true)
28
+ add_command(CemUpdateConfigFromDiff.new)
29
+ end
30
+ end
31
+
32
+ class CemUpdateConfigFromDiff < AbideCommand
33
+ CMD_NAME = 'from-diff'
34
+ CMD_SHORT = 'Update by diffing two XCCDF files'
35
+ CMD_LONG = 'Update by diffing two XCCDF files'
36
+ CMD_CONFIG_FILE = 'Path to the Puppet CEM config file'
37
+ CMD_CURRENT_XCCDF = 'Path to the current XCCDF file'
38
+ CMD_NEW_XCCDF = 'Path to the new XCCDF file'
39
+ def initialize
40
+ super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
41
+ argument_desc(CONFIG_FILE: CMD_CONFIG_FILE, CURRENT_XCCDF: CMD_CURRENT_XCCDF, NEW_XCCDF: CMD_NEW_XCCDF)
42
+ options.on('-o [FILE]', '--out-file [FILE]', 'Path to save the updated config file') do |o|
43
+ @data[:out_file] = o
44
+ end
45
+ options.on('-v', '--verbose', 'Verbose output') do
46
+ @data[:verbose] = true
47
+ end
48
+ options.on('-q', '--quiet', 'Quiet output') do
49
+ @data[:quiet] = true
50
+ end
51
+ end
52
+
53
+ def help_arguments
54
+ <<~ARGHELP
55
+ Arguments:
56
+ CONFIG_FILE: #{CMD_CONFIG_FILE}
57
+ CURRENT_XCCDF: #{CMD_CURRENT_XCCDF}
58
+ NEW_XCCDF: #{CMD_NEW_XCCDF}
59
+ ARGHELP
60
+ end
61
+
62
+ def execute(config_file, cur_xccdf, new_xccdf)
63
+ AbideDevUtils::Validate.file(config_file, extension: 'yaml')
64
+ AbideDevUtils::Validate.file(cur_xccdf, extension: 'xml')
65
+ config_hiera = AbideDevUtils::Files::Reader.read(config_file, safe: true)
66
+ diff = AbideDevUtils::XCCDF::Diff::BenchmarkDiff.new(cur_xccdf, new_xccdf).diff[:diff][:number_title]
67
+ new_config_hiera, change_report = AbideDevUtils::CEM.update_legacy_config_from_diff(config_hiera, diff)
68
+ AbideDevUtils::Output.yaml(new_config_hiera, console: @data[:verbose], file: @data[:out_file])
69
+ AbideDevUtils::Output.simple(change_report) unless @data[:quiet]
70
+ end
71
+ end
72
+ end
73
+ end
@@ -37,7 +37,7 @@ module Abide
37
37
 
38
38
  def execute
39
39
  client = JIRA.client
40
- myself = JIRA.get_myself(client)
40
+ myself = JIRA.myself(client)
41
41
  return if myself.attrs['name'].empty?
42
42
 
43
43
  Abide::CLI::OUTPUT.simple("Successfully authenticated user #{myself.attrs['name']}!")
@@ -34,6 +34,9 @@ module Abide
34
34
  options.on('-d [DIR]', '--files-output-directory [DIR]', 'Directory to save files data/mappings by default') do |d|
35
35
  @data[:dir] = d
36
36
  end
37
+ options.on('-V', '--version-output-dir', 'If saving to a directory, version the output directory') do
38
+ @data[:version_output_dir] = true
39
+ end
37
40
  options.on('-q', '--quiet', 'Show no output in the terminal') { @data[:quiet] = true }
38
41
  options.on('-p [PREFIX]', '--parent-key-prefix [PREFIX]', 'A prefix to append to the parent key') do |p|
39
42
  @data[:parent_key_prefix] = p
@@ -104,13 +107,24 @@ module Abide
104
107
  options.on('-p [PROFILE]', '--profile', 'Only diff and specific profile in the benchmarks') do |x|
105
108
  @data[:profile] = x
106
109
  end
110
+ options.on('-l [LEVEL]', '--level', 'Only diff the specific level in the benchmarks') do |x|
111
+ @data[:level] = x
112
+ end
113
+ options.on('-r', '--raw', 'Output the diff in raw hash format') { @data[:raw] = true }
107
114
  options.on('-q', '--quiet', 'Show no output in the terminal') { @data[:quiet] = false }
108
115
  options.on('--no-diff-profiles', 'Do not diff the profiles in the XCCDF files') { @data[:diff_profiles] = false }
109
116
  options.on('--no-diff-controls', 'Do not diff the controls in the XCCDF files') { @data[:diff_controls] = false }
117
+ options.on('--old-style', 'Use old-style diffs') { @data[:old_style] = true }
110
118
  end
111
119
 
112
120
  def execute(file1, file2)
113
- diffreport = AbideDevUtils::XCCDF.diff(file1, file2, @data)
121
+ diffreport = if @data[:old_style]
122
+ AbideDevUtils::XCCDF.diff(file1, file2, @data)
123
+ else
124
+ dr = AbideDevUtils::XCCDF.new_style_diff(file1, file2, @data)
125
+ dr[:diff][:number_title].map! { |d| d[:text] }
126
+ dr
127
+ end
114
128
  AbideDevUtils::Output.yaml(diffreport, console: @data.fetch(:quiet, true), file: @data.fetch(:outfile, nil))
115
129
  end
116
130
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'cmdparse'
4
4
  require 'abide_dev_utils/version'
5
+ require 'abide_dev_utils/cli/cem'
5
6
  require 'abide_dev_utils/constants'
6
7
  require 'abide_dev_utils/cli/comply'
7
8
  require 'abide_dev_utils/cli/puppet'
@@ -22,6 +23,7 @@ module Abide
22
23
  parser.main_options.banner = ROOT_CMD_BANNER
23
24
  parser.add_command(CmdParse::HelpCommand.new, default: true)
24
25
  parser.add_command(CmdParse::VersionCommand.new(add_switches: true))
26
+ parser.add_command(CemCommand.new)
25
27
  parser.add_command(ComplyCommand.new)
26
28
  parser.add_command(PuppetCommand.new)
27
29
  parser.add_command(XccdfCommand.new)
@@ -1,7 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'abide_dev_utils/validate'
4
+
3
5
  module AbideDevUtils
4
6
  module Files
7
+ class Reader
8
+ def self.read(path, raw: false, safe: true, opts: {})
9
+ AbideDevUtils::Validate.file(path)
10
+ return File.read(path) if raw
11
+
12
+ extension = File.extname(path)
13
+ case extension
14
+ when /\.yaml|\.yml/
15
+ require 'yaml'
16
+ if safe
17
+ YAML.safe_load(File.read(path))
18
+ else
19
+ YAML.load_file(path)
20
+ end
21
+ when '.json'
22
+ require 'json'
23
+ return JSON.parse(File.read(path), opts) if safe
24
+
25
+ JSON.parse!(File.read(path), opts)
26
+ when '.xml'
27
+ require 'nokogiri'
28
+ File.open(path, 'r') do |file|
29
+ Nokogiri::XML.parse(file) do |config|
30
+ config.strict.noblanks.norecover
31
+ end
32
+ end
33
+ else
34
+ File.read(path)
35
+ end
36
+ end
37
+ end
38
+
5
39
  class Writer
6
40
  MSG_EXT_APPEND = 'Appending %s extension to file'
7
41
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AbideDevUtils
4
- VERSION = "0.9.5"
4
+ VERSION = "0.10.1"
5
5
  end