lib/inspec/config.rb in inspec-4.7.3 vs lib/inspec/config.rb in inspec-4.7.18

- old
+ new

@@ -58,10 +58,11 @@ self.class.cached = self end 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:" @@ -157,10 +158,11 @@ # Look into target %r{^(?<transport_name>[a-z_\-0-9]+)://.*$} =~ final_options[:target] unless transport_name raise ArgumentError, "Could not recognize a backend from the target #{final_options[:target]} - use a URI format with the backend name as the URI schema. Example: 'ssh://somehost.com' or 'transport://credset' or 'transport://' if credentials are provided outside of InSpec." end + credentials[:backend] = transport_name.to_s # these are indeed stored in Train as Strings. end def _utc_merge_credset(credentials, transport_name) # Look for Config File credentials/transport_name/credset @@ -183,10 +185,11 @@ end end def _utc_find_credset_name(_credentials, transport_name) return nil unless final_options[:target] + match = final_options[:target].match(%r{^#{transport_name}://(?<credset_name>[\w\d\-]+)$}) match ? match[:credset_name] : nil end #-----------------------------------------------------------------------# @@ -194,10 +197,11 @@ #-----------------------------------------------------------------------# # Regardless of our situation, end up with a readable IO object def resolve_cfg_io(cli_opts, cfg_io) raise(ArgumentError, "Inspec::Config must use an IO to read from") if cfg_io && !cfg_io.respond_to?(:read) + cfg_io ||= check_for_piped_config(cli_opts) return cfg_io if cfg_io path = determine_cfg_path(cli_opts) @@ -209,10 +213,11 @@ cli_opt = cli_opts[:config] || cli_opts[:json_config] Inspec.deprecate(:cli_option_json_config) if cli_opts.key?(:json_config) return nil unless cli_opt return nil unless cli_opt == "-" + # This warning is here so that if a user invokes inspec with --config=-, # they will have an explanation for why it appears to hang. Inspec::Log.warn "Reading JSON config from standard input" if STDIN.tty? STDIN end @@ -285,17 +290,18 @@ end valid_fields = %w{version cli_options credentials compliance reporter}.sort @cfg_file_contents.keys.each do |seen_field| unless valid_fields.include?(seen_field) - raise Inspec::ConfigError::Invalid, "Unrecognized top-level configuration field #{seen_field}. Recognized fields: #{valid_fields.join(', ')}" + raise Inspec::ConfigError::Invalid, "Unrecognized top-level configuration field #{seen_field}. Recognized fields: #{valid_fields.join(", ")}" end end end def validate_reporters!(reporters) return if reporters.nil? + # TODO: move this into a reporter plugin type system valid_types = %w{ automate cli documentation @@ -311,10 +317,11 @@ reporters.each do |reporter_name, reporter_config| raise NotImplementedError, "'#{reporter_name}' is not a valid reporter type." unless valid_types.include?(reporter_name) next unless reporter_name == "automate" + %w{token url}.each do |option| raise Inspec::ReporterError, "You must specify a automate #{option} via the config file." if reporter_config[option].nil? end end @@ -408,9 +415,10 @@ # whenever it is used, it requires a value. Handle options that were # defined in such a way and require a value here: %w{password sudo-password}.each do |option_name| snake_case_option_name = option_name.tr("-", "_").to_s next unless options[snake_case_option_name] == -1 # Thor sets -1 for missing value - see #1918 + raise ArgumentError, "Please provide a value for --#{option_name}. For example: --#{option_name}=hello." end # Infer `--sudo` if using `--sudo-password` without `--sudo` if options["sudo_password"] && !options["sudo"]