Class: Inspec::Config
- Inherits:
-
Object
- Object
- Inspec::Config
- Extended by:
- Forwardable
- Defined in:
- lib/inspec/config.rb
Defined Under Namespace
Classes: Defaults
Constant Summary collapse
- GENERIC_CREDENTIALS =
These are options that apply to any transport
%w{ backend logger sudo sudo_password sudo_command sudo_options shell shell_options shell_command }.freeze
Instance Attribute Summary collapse
-
#final_options ⇒ Object
readonly
Returns the value of attribute final_options.
Class Method Summary collapse
-
.mock(opts = {}) ⇒ Object
This makes it easy to make a config with a mock backend.
Instance Method Summary collapse
- #diagnose ⇒ Object
-
#initialize(cli_opts = {}, cfg_io = nil, command_name = nil) ⇒ Config
constructor
A new instance of Config.
-
#unpack_train_credentials ⇒ Object
Returns a Hash with Symbol keys as follows: backend: machine name of the Train transport needed If present, any of the GENERIC_CREDENTIALS.
Constructor Details
#initialize(cli_opts = {}, cfg_io = nil, command_name = nil) ⇒ Config
Returns a new instance of Config.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/inspec/config.rb', line 33 def initialize(cli_opts = {}, cfg_io = nil, command_name = nil) @command_name = command_name || (ARGV.empty? ? nil : ARGV[0].to_sym) @defaults = Defaults.for_command(@command_name) @cli_opts = cli_opts.dup cfg_io = resolve_cfg_io(@cli_opts, cfg_io) @cfg_file_contents = read_cfg_file_io(cfg_io) @merged_options = @final_options = end |
Instance Attribute Details
#final_options ⇒ Object (readonly)
Returns the value of attribute final_options.
26 27 28 |
# File 'lib/inspec/config.rb', line 26 def @final_options end |
Class Method Details
Instance Method Details
#diagnose ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/inspec/config.rb', line 45 def diagnose return unless self[:diagnose] puts "InSpec version: #{Inspec::VERSION}" puts "Train version: #{Train::VERSION}" puts 'Command line configuration:' pp @cli_opts puts 'JSON configuration file:' pp @cfg_file_contents puts 'Merged configuration:' pp @merged_options puts end |
#unpack_train_credentials ⇒ Object
Returns a Hash with Symbol keys as follows:
backend: machine name of the Train transport needed
If present, any of the GENERIC_CREDENTIALS.
All other keys are specific to the backend.
The credentials are gleaned from:
* the Train transport defaults. Train handles this on transport creation,
so this method doesn't load defaults.
* individual InSpec CLI options (which in many cases may have the
transport name prefixed, which is stripped before being added
to the creds hash)
* the --target CLI option, which is interpreted:
- as an arbitrary URI, which is parsed by Train.unpack_target_from_uri
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/inspec/config.rb', line 76 def unpack_train_credentials # Internally, use indifferent access while we build the creds credentials = Thor::CoreExt::HashWithIndifferentAccess.new({}) # Helper methods prefixed with _utc_ (Unpack Train Credentials) credentials.merge!(_utc_generic_credentials) _utc_determine_backend(credentials) credentials.merge!(Train.unpack_target_from_uri([:target] || '')) # TODO: this will be replaced with the credset work transport_name = credentials[:backend].to_s (credentials, transport_name) # Convert to all-Symbol keys credentials.each_with_object({}) do |(option, value), creds| creds[option.to_sym] = value creds end end |