Class: Abide::CLI::CemUpdateConfigFromDiff

Inherits:
AbideCommand
  • Object
show all
Defined in:
lib/abide_dev_utils/cli/cem.rb

Constant Summary collapse

CMD_NAME =
'from-diff'
CMD_SHORT =
'Update by diffing two XCCDF files'
CMD_LONG =
'Update by diffing two XCCDF files'
CMD_CONFIG_FILE =
'Path to the Puppet CEM config file'
CMD_CURRENT_XCCDF =
'Path to the current XCCDF file'
CMD_NEW_XCCDF =
'Path to the new XCCDF file'

Constants included from AbideDevUtils::Config

AbideDevUtils::Config::DEFAULT_PATH

Instance Method Summary collapse

Methods included from AbideDevUtils::Config

config_section, #config_section, fetch, #fetch, to_h, #to_h

Constructor Details

#initializeCemUpdateConfigFromDiff

Returns a new instance of CemUpdateConfigFromDiff.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/abide_dev_utils/cli/cem.rb', line 39

def initialize
  super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
  argument_desc(CONFIG_FILE: CMD_CONFIG_FILE, CURRENT_XCCDF: CMD_CURRENT_XCCDF, NEW_XCCDF: CMD_NEW_XCCDF)
  options.on('-o [FILE]', '--out-file [FILE]', 'Path to save the updated config file') do |o|
    @data[:out_file] = o
  end
  options.on('-v', '--verbose', 'Verbose output') do
    @data[:verbose] = true
  end
  options.on('-q', '--quiet', 'Quiet output') do
    @data[:quiet] = true
  end
end

Instance Method Details

#execute(config_file, cur_xccdf, new_xccdf) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/abide_dev_utils/cli/cem.rb', line 62

def execute(config_file, cur_xccdf, new_xccdf)
  AbideDevUtils::Validate.file(config_file, extension: 'yaml')
  AbideDevUtils::Validate.file(cur_xccdf, extension: 'xml')
  config_hiera = AbideDevUtils::Files::Reader.read(config_file, safe: true)
  diff = AbideDevUtils::XCCDF::Diff::BenchmarkDiff.new(cur_xccdf, new_xccdf).diff[:diff][:number_title]
  new_config_hiera, change_report = AbideDevUtils::CEM.update_legacy_config_from_diff(config_hiera, diff)
  AbideDevUtils::Output.yaml(new_config_hiera, console: @data[:verbose], file: @data[:out_file])
  AbideDevUtils::Output.simple(change_report) unless @data[:quiet]
end

#help_argumentsObject



53
54
55
56
57
58
59
60
# File 'lib/abide_dev_utils/cli/cem.rb', line 53

def help_arguments
  <<~ARGHELP
    Arguments:
      CONFIG_FILE:   #{CMD_CONFIG_FILE}
      CURRENT_XCCDF: #{CMD_CURRENT_XCCDF}
      NEW_XCCDF:     #{CMD_NEW_XCCDF}
  ARGHELP
end