abide_dev_utils 0.15.0 → 0.16.0

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: a8f5dc40bfe8e447b1440435f020db1fb63decccaa405d52301251d9b5786af9
4
- data.tar.gz: 414c7c96cfb731b65ff942cac68cf078ac2d7e4bac01da3a567f0ace10599243
3
+ metadata.gz: 220a0a755c0e337d22a853e106935f4355564e51a759eb93967e3aeba5a9f020
4
+ data.tar.gz: e0272122e07a4e53d3efa71486de5dc7a0229ca0d22214b3311c94df0c90100b
5
5
  SHA512:
6
- metadata.gz: bee0317d5e0c9b745537771c5c9425fb74d8c3a1a745dbaf2b694d9e258730608bf1616404efb59380a6178e51308385f1c4d6bb120fc9f35dd953432569c518
7
- data.tar.gz: 47b08b70d6e148804606222ecd9a5d53740483f57c87613bead2fb8292d6f668a4a2507a046c5edb452a353d27ca6193d04f4736d347ac8c6f04291a1dbd61d0
6
+ metadata.gz: c7710f102655653f4181694c8dd076acff1dfd8040120c54157bc77a89f3db4a892854d2110ac4a47974ead2fdc23c3b3028c4459aa9e7bf75145e71fcebad0b
7
+ data.tar.gz: a5d0d101010f6ba4129346c4c4447f433b5a61e36e9000c3dab653a1709b78ff08203ec2dd014e61489d09eb2a78badfb51e233d8cbe33d85c903c3654cae90f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abide_dev_utils (0.15.0)
4
+ abide_dev_utils (0.16.0)
5
5
  cmdparse (~> 3.0)
6
6
  facterdb (>= 1.21)
7
7
  google-cloud-storage (~> 1.34)
@@ -85,7 +85,7 @@ module AbideDevUtils
85
85
  next if benchmark.framework == 'stig' && control.id_map_type != 'vulnid'
86
86
 
87
87
  control_md = ControlMarkdown.new(control, @md, @strings, @module_name, benchmark.framework, opts: @opts)
88
- control_md.generate!
88
+ control_md.generate! if control_md.verify_profile_and_level_selections
89
89
  progress_bar.increment unless @opts[:quiet]
90
90
  rescue StandardError => e
91
91
  raise "Failed to generate markdown for control #{control.id}. Original message: #{e.message}"
@@ -248,6 +248,8 @@ module AbideDevUtils
248
248
  @framework = framework
249
249
  @formatter = formatter.nil? ? TypeExprValueFormatter : formatter
250
250
  @opts = opts
251
+ @valid_level = []
252
+ @valid_profile = []
251
253
  @control_data = {}
252
254
  end
253
255
 
@@ -262,6 +264,43 @@ module AbideDevUtils
262
264
  resource_reference_builder
263
265
  end
264
266
 
267
+ # This function act as a filter for controls based on the profile and level selections.
268
+ # There are few scanarios that can happen:
269
+ # 1. If no selections are made for profile or level, then all profiles and levels of control will be selected.
270
+ # 2. If selections are made for profile, then only the selected profile and all levels of control will be selected.
271
+ # 3. If selections are made for level, then only the selected level and all profiles of control will be selected.
272
+ # This function adds in some runtime overhead because we're checking each control's level and profile which is
273
+ # what we're going to be doing later when building the level and profile markdown, but this is
274
+ # necessary to ensure that the reference.md is generated the way we want it to be.
275
+ def verify_profile_and_level_selections
276
+ return true if @opts[:select_profile].nil? && @opts[:select_level].nil?
277
+
278
+ if @opts[:select_profile].nil? && !@opts[:select_level].nil?
279
+ @control.levels.each do |level|
280
+ @valid_level << level if select_control_level(level)
281
+ end
282
+
283
+ return true unless @valid_level.empty?
284
+ elsif !@opts[:select_profile].nil? && @opts[:select_level].nil?
285
+ @control.profiles.each do |profile|
286
+ @valid_profile << profile if select_control_profile(profile)
287
+ end
288
+
289
+ return true unless @valid_profile.empty?
290
+ elsif !@opts[:select_profile].nil? && !@opts[:select_level].nil?
291
+ @control.levels.each do |level|
292
+ @valid_level << level if select_control_level(level)
293
+ end
294
+
295
+ @control.profiles.each do |profile|
296
+ @valid_profile << profile if select_control_profile(profile)
297
+ end
298
+
299
+ # As long as there are valid profiles and levels for the control at this stage, all is good
300
+ !@valid_level.empty? && !@valid_profile.empty?
301
+ end
302
+ end
303
+
265
304
  private
266
305
 
267
306
  def heading_builder
@@ -340,18 +379,36 @@ module AbideDevUtils
340
379
  def control_levels_builder
341
380
  return unless @control.levels
342
381
 
382
+ # @valid_level is populated in verify_profile_and_level_selections from the fact that we've given
383
+ # the generator a list of levels we want to use. If we didn't give it a list of levels, then we
384
+ # want to use all of the levels that the control supports from @control.
343
385
  @md.add_ul('Supported Levels:')
344
- @control.levels.each do |l|
345
- @md.add_ul(@md.code(l), indent: 1)
386
+ if @valid_level.empty?
387
+ @control.levels.each do |l|
388
+ @md.add_ul(@md.code(l), indent: 1)
389
+ end
390
+ else
391
+ @valid_level.each do |l|
392
+ @md.add_ul(@md.code(l), indent: 1)
393
+ end
346
394
  end
347
395
  end
348
396
 
349
397
  def control_profiles_builder
350
398
  return unless @control.profiles
351
399
 
400
+ # @valid_profile is populated in verify_profile_and_level_selections from the fact that we've given
401
+ # the generator a list of profiles we want to use. If we didn't give it a list of profiles, then we
402
+ # want to use all of the profiles that the control supports from @control.
352
403
  @md.add_ul('Supported Profiles:')
353
- @control.profiles.each do |l|
354
- @md.add_ul(@md.code(l), indent: 1)
404
+ if @valid_profile.empty?
405
+ @control.profiles.each do |l|
406
+ @md.add_ul(@md.code(l), indent: 1)
407
+ end
408
+ else
409
+ @valid_profile.each do |l|
410
+ @md.add_ul(@md.code(l), indent: 1)
411
+ end
355
412
  end
356
413
  end
357
414
 
@@ -364,6 +421,18 @@ module AbideDevUtils
364
421
  end
365
422
  end
366
423
 
424
+ # Function that returns true if the profile is in the list of profiles that we want to use.
425
+ # @param profile [String] the profile to filter
426
+ def select_control_profile(profile)
427
+ @opts[:select_profile].include? profile
428
+ end
429
+
430
+ # Function that returns true if the level is in the list of levels that we want to use.
431
+ # @param level [String] the level to filter
432
+ def select_control_level(level)
433
+ @opts[:select_level].include? level
434
+ end
435
+
367
436
  def dependent_controls_builder
368
437
  dep_ctrls = @control.resource.dependent_controls
369
438
  return if dep_ctrls.nil? || dep_ctrls.empty?
@@ -113,6 +113,12 @@ module Abide
113
113
  options.on('-s', '--strict', 'Fails if there are any errors') do
114
114
  @data[:strict] = true
115
115
  end
116
+ options.on('-p [PROFILE]', '--select-profile [PROFILE]', 'The list of profiles that the reference.md will use separated by commas') do |pr|
117
+ @data[:select_profile] = pr.split(',')
118
+ end
119
+ options.on('-l [LEVEL]', '--select-level [LEVEL]', 'The list of level that the reference.md will use separated by commas') do |l|
120
+ @data[:select_level] = l.split(',')
121
+ end
116
122
  end
117
123
 
118
124
  def execute
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AbideDevUtils
4
- VERSION = "0.15.0"
4
+ VERSION = "0.16.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abide_dev_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - abide-team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-28 00:00:00.000000000 Z
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -448,7 +448,7 @@ metadata:
448
448
  homepage_uri: https://github.com/puppetlabs/abide_dev_utils
449
449
  source_code_uri: https://github.com/puppetlabs/abide_dev_utils
450
450
  changelog_uri: https://github.com/puppetlabs/abide_dev_utils
451
- post_install_message:
451
+ post_install_message:
452
452
  rdoc_options: []
453
453
  require_paths:
454
454
  - lib
@@ -463,8 +463,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
463
463
  - !ruby/object:Gem::Version
464
464
  version: '0'
465
465
  requirements: []
466
- rubygems_version: 3.4.6
467
- signing_key:
466
+ rubygems_version: 3.1.6
467
+ signing_key:
468
468
  specification_version: 4
469
469
  summary: Helper utilities for developing compliance Puppet code
470
470
  test_files: []