Class: Inspec::Config
- Inherits:
-
Object
- Object
- Inspec::Config
- Extended by:
- Forwardable
- Includes:
- Plugin::V2::FilterPredicates
- 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
- KNOWN_VERSIONS =
[ "1.1", "1.2", ].freeze
Instance Attribute Summary collapse
-
#final_options ⇒ Object
readonly
Returns the value of attribute final_options.
Class Method Summary collapse
-
.__reset ⇒ Object
clear the cached config.
-
.cached ⇒ Object
Use this to get a cached version of the config.
- .cached=(cfg) ⇒ Object
-
.mock(opts = {}) ⇒ Object
This makes it easy to make a config with a mock backend.
Instance Method Summary collapse
- #diagnose ⇒ Object
-
#fetch_plugin_config(plugin_name) ⇒ Object
———————————————————————–# Fetching Plugin Data ———————————————————————–#.
-
#initialize(cli_opts = {}, cfg_io = nil, command_name = nil) ⇒ Config
constructor
This gets called when the first config is created.
-
#telemetry_options ⇒ Hash
return all telemetry options from 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.
Methods included from Plugin::V2::FilterPredicates
#inspec_plugin_name?, #train_plugin_name?, #valid_plugin_name?
Constructor Details
#initialize(cli_opts = {}, cfg_io = nil, command_name = nil) ⇒ Config
This gets called when the first config is created.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/inspec/config.rb', line 56 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) @plugin_cfg = {} @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 = self.class.cached = self end |
Instance Attribute Details
#final_options ⇒ Object (readonly)
Returns the value of attribute final_options.
38 39 40 |
# File 'lib/inspec/config.rb', line 38 def @final_options end |
Class Method Details
.__reset ⇒ Object
clear the cached config
139 140 141 |
# File 'lib/inspec/config.rb', line 139 def self.__reset @cached_config = nil end |
.cached ⇒ Object
Use this to get a cached version of the config. This prevents you from being required to pass it around everywhere.
47 48 49 |
# File 'lib/inspec/config.rb', line 47 def self.cached @cached_config end |
.cached=(cfg) ⇒ Object
51 52 53 |
# File 'lib/inspec/config.rb', line 51 def self.cached=(cfg) @cached_config ||= cfg end |
Instance Method Details
#diagnose ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/inspec/config.rb', line 70 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 |
#fetch_plugin_config(plugin_name) ⇒ Object
134 135 136 |
# File 'lib/inspec/config.rb', line 134 def fetch_plugin_config(plugin_name) Thor::CoreExt::HashWithIndifferentAccess.new(@plugin_cfg[plugin_name] || {}) end |
#telemetry_options ⇒ Hash
return all telemetry options from config
86 87 88 |
# File 'lib/inspec/config.rb', line 86 def .select { |key, _| key.include?("telemetry") } 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 a transport://credset format, which looks up the creds in
the config file in the credentials section
- as an arbitrary URI, which is parsed by Train.unpack_target_from_uri
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/inspec/config.rb', line 110 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) transport_name = credentials[:backend].to_s _utc_merge_credset(credentials, transport_name) (credentials, transport_name) # Convert to all-Symbol keys credentials.each_with_object({}) do |(option, value), creds| creds[option.to_sym] = value creds end end |