Class: Abide::CLI::ComplyReportCommand

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

Constant Summary collapse

CMD_NAME =
'report'
CMD_SHORT =
'Generates a yaml report of Puppet Comply scan results'
CMD_LONG =
"Generates a yaml file that shows the scan results of all nodes in Puppet Comply.\nThis command utilizes Selenium WebDriver and the Google Chrome browser to automate\nclicking through the Comply UI and building a report. In order to use this command,\nyou MUST have Google Chrome installed and you MUST install the chromedriver binary.\nMore info and instructions can be found here:\nhttps://www.selenium.dev/documentation/en/getting_started_with_webdriver/.\n"
CMD_COMPLY_URL =
'The URL (including https://) of Puppet Comply'
CMD_COMPLY_PASSWORD =
'The password for Puppet Comply'
OPT_TIMEOUT_DESC =
"The number of seconds you would like requests to wait before timing out. Defaults\nto 10 seconds.\n"
OPT_STATUS_DESC =
"A comma-separated list of check statuses to ONLY include in the report.\nValid statuses are: pass, fail, error, notapplicable, notchecked, unknown, informational\n"
OPT_IGNORE_NODES =
"A comma-separated list of node certnames to ignore building reports for. This\noptions is mutually exclusive with --only and, if both are set, --only will take precedence\nover this option.\n"
OPT_ONLY_NODES =
"A comma-separated list of node certnames to ONLY build reports for. No other\nnodes will have reports built for them except the ones specified. This option\nis mutually exclusive with --ignore and, if both are set, this options will\ntake precedence over --ignore.\n"

Constants included from AbideDevUtils::Config

AbideDevUtils::Config::DEFAULT_PATH

Instance Method Summary collapse

Methods inherited from AbideCommand

#deprecated?, #on_after_add

Methods included from AbideDevUtils::Config

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

Constructor Details

#initializeComplyReportCommand

Returns a new instance of ComplyReportCommand.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/abide_dev_utils/cli/comply.rb', line 51

def initialize
  super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
  argument_desc(COMPLY_URL: CMD_COMPLY_URL, COMPLY_PASSWORD: CMD_COMPLY_PASSWORD)
  options.on('-o [FILE]', '--out-file [FILE]', 'Path to save the report') { |f| @data[:file] = f }
  options.on('-u [USERNAME]', '--username [USERNAME]', 'The username for Comply (defaults to comply)') do |u|
    @data[:username] = u
  end
  options.on('-t [SECONDS]', '--timeout [SECONDS]', OPT_TIMEOUT_DESC) do |t|
    @data[:timeout] = t
  end
  options.on('-s [X,Y,Z]', '--status [X,Y,Z]',
             %w[pass fail error notapplicable notchecked unknown informational],
             Array,
             OPT_STATUS_DESC) do |s|
    s&.map! { |i| i == 'notchecked' ? 'not checked' : i }
    @data[:status] = s
  end
  options.on('--only [X,Y,Z]', Array, OPT_ONLY_NODES) do |o|
    @data[:onlylist] = o
  end
  options.on('--ignore [X,Y,Z]', Array, OPT_IGNORE_NODES) do |i|
    @data[:ignorelist] = i
  end
  options.on('--page-source-on-error', 'Dump page source to file on error') do
    @data[:page_source_on_error] = true
  end
end

Instance Method Details

#execute(comply_url = nil, comply_password = nil) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/abide_dev_utils/cli/comply.rb', line 88

def execute(comply_url = nil, comply_password = nil)
  Abide::CLI::VALIDATE.filesystem_path(`command -v chromedriver`.strip)
  conf = config_section('comply')
  comply_url = conf.fetch(:url) if comply_url.nil?
  comply_password = comply_password.nil? ? conf.fetch(:password, Abide::CLI::PROMPT.password) : comply_password
  report = AbideDevUtils::Comply.build_report(comply_url, comply_password, conf, **@data)
  outfile = @data.fetch(:file, nil).nil? ? conf.fetch(:report_path, 'comply_scan_report.yaml') : @data[:file]
  Abide::CLI::OUTPUT.yaml(report, file: outfile)
end

#help_argumentsObject



79
80
81
82
83
84
85
86
# File 'lib/abide_dev_utils/cli/comply.rb', line 79

def help_arguments
  "    Arguments:\n        COMPLY_URL        \#{CMD_COMPLY_URL}\n        COMPLY_PASSWORD   \#{CMD_COMPLY_PASSWORD}\n\n  ARGHELP\nend\n"