Class: InspecPlugins::Parallelism::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb

Constant Summary collapse

PARALLEL_SAFE_REPORTERS =

TODO: make this list dynamic so plugins can self-declare

[
  "automate",      # Performs HTTP transactions, silent on STDOUT
  "child-status",  # Writes dedicated protocol to STDOUT, expected by parent
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(invocations, cli_options, sub_cmd = "exec") ⇒ Validator

Returns a new instance of Validator.



14
15
16
17
18
19
20
21
22
# File 'lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb', line 14

def initialize(invocations, cli_options, sub_cmd = "exec")
  @invocations = invocations
  @sub_cmd = sub_cmd
  @thor_options_for_sub_cmd = Inspec::InspecCLI.commands[sub_cmd].options
  @aliases_mapping = create_aliases_mapping
  @cli_options = cli_options
  @config_content = nil
  @stdin_config = nil
end

Instance Attribute Details

#aliases_mappingObject

Returns the value of attribute aliases_mapping.



12
13
14
# File 'lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb', line 12

def aliases_mapping
  @aliases_mapping
end

#cli_optionsObject

Returns the value of attribute cli_options.



12
13
14
# File 'lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb', line 12

def cli_options
  @cli_options
end

#config_contentObject

Returns the value of attribute config_content.



12
13
14
# File 'lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb', line 12

def config_content
  @config_content
end

#invocationsObject

Returns the value of attribute invocations.



12
13
14
# File 'lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb', line 12

def invocations
  @invocations
end

#stdin_configObject

Returns the value of attribute stdin_config.



12
13
14
# File 'lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb', line 12

def stdin_config
  @stdin_config
end

#sub_cmdObject

Returns the value of attribute sub_cmd.



12
13
14
# File 'lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb', line 12

def sub_cmd
  @sub_cmd
end

#thor_options_for_sub_cmdObject

Returns the value of attribute thor_options_for_sub_cmd.



12
13
14
# File 'lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb', line 12

def thor_options_for_sub_cmd
  @thor_options_for_sub_cmd
end

Instance Method Details

#validateObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb', line 24

def validate
  invocations.each do |invocation_data|
    invocation_data[:validation_errors] = []

    convert_cli_to_thor_options(invocation_data)
    check_for_spurious_options(invocation_data)
    check_for_required_fields(invocation_data)
    check_for_reporter_options(invocation_data)

  end
end

#validate_log_pathObject



36
37
38
39
40
41
42
43
44
# File 'lib/plugins/inspec-parallel/lib/inspec-parallel/validator.rb', line 36

def validate_log_path
  return [] unless cli_options["log_path"]

  if File.directory?(cli_options["log_path"])
    []
  else
    [true, "Log path #{cli_options["log_path"]} is not accessible"]
  end
end