inspec-core 4.19.2 → 4.20.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3f655ad7598f4a71bab9caff608eca6990e6c66242d1c11519d105c89168fcb
4
- data.tar.gz: f6679028fc6283e7482143368d09edf70cb74d648bd45ede5d2bb8e4eb6ec165
3
+ metadata.gz: 2395ce22d38edca9eaac2fad00c1fc61f3fb95a154618540d23bc2a1e6ce0fcd
4
+ data.tar.gz: 4ebdbe5526025408e729b52e0614b43fe89f70b0faae5eeecc8c23db8f0f1ff9
5
5
  SHA512:
6
- metadata.gz: ea24f149c474dc40974f05d017d3544ce2f4e3b762f1474f7c9146d01cf3c074a8526406bc7bb1b325cd973251f0ffc5cad06a86d7686dda0e7bf6a226f834c0
7
- data.tar.gz: cb74991d735738e58dbf04ed6c0dc5e32c923d83fe61cc7143a8af611050f001bb0d174949ed34a8ba7f97cd16735ca96e8d845e970abda579a12f44dec6fc22
6
+ metadata.gz: f2b21bfbc96b4830edf20f1d48493257845bfbeb52137141269371066c47359092d3ed280cc64e9358b3587d0ddb0c54a643cafd730d57ad2d7ba2331d35b33a
7
+ data.tar.gz: 84bc11b59621836d20c045efcdee955cc97c605e5902fafaa79c8756dd44f66334731256c6ba4273484d645484f374b1ec2daf471a6dc56805ea819ab2685f38
@@ -140,7 +140,7 @@ module Inspec
140
140
  option :reporter_backtrace_inclusion, type: :boolean,
141
141
  desc: "Include a code backtrace in report data (default: true)"
142
142
  option :input, type: :array, banner: "name1=value1 name2=value2",
143
- desc: "Specify one or more inputs directly on the command line, as --input NAME=VALUE"
143
+ desc: "Specify one or more inputs directly on the command line, as --input NAME=VALUE. Accepts single-quoted YAML and JSON structures."
144
144
  option :input_file, type: :array,
145
145
  desc: "Load one or more input files, a YAML file with values for the profile to use"
146
146
  option :waiver_file, type: :array,
@@ -155,6 +155,9 @@ module Inspec
155
155
  desc: "Show progress while executing tests."
156
156
  option :distinct_exit, type: :boolean, default: true,
157
157
  desc: "Exit with code 101 if any tests fail, and 100 if any are skipped (default). If disabled, exit 0 on skips and 1 for failures."
158
+ option :silence_deprecations, type: :array,
159
+ banner: "[all]|[GROUP GROUP...]",
160
+ desc: "Suppress deprecation warnings. See install_dir/etc/deprecations.json for list of GROUPs or use 'all'."
158
161
  end
159
162
 
160
163
  def self.format_platform_info(params: {}, indent: 0, color: 39)
@@ -166,8 +166,9 @@ module Inspec
166
166
  end
167
167
  end
168
168
  input_name, input_value = pair.split("=")
169
+ input_value = parse_cli_input_value(input_name, input_value)
169
170
  evt = Inspec::Input::Event.new(
170
- value: input_value.chomp(","), # Trim trailing comma if any
171
+ value: input_value,
171
172
  provider: :cli,
172
173
  priority: 50
173
174
  )
@@ -175,6 +176,37 @@ module Inspec
175
176
  end
176
177
  end
177
178
 
179
+ # Remove trailing commas, resolve type.
180
+ def parse_cli_input_value(input_name, given_value)
181
+ value = given_value.chomp(",") # Trim trailing comma if any
182
+ case value
183
+ when /^true|false$/i
184
+ value = !!(value =~ /true/i)
185
+ when /^-?\d+$/
186
+ value = value.to_i
187
+ when /^-?\d+\.\d+$/
188
+ value = value.to_f
189
+ when /^(\[|\{).*(\]|\})$/
190
+ # Look for complex values and try to parse them.
191
+ require "yaml"
192
+ begin
193
+ value = YAML.load(value)
194
+ rescue Psych::SyntaxError => yaml_error
195
+ # It could be that we just tried to run JSON through the YAML parser.
196
+ require "json"
197
+ begin
198
+ value = JSON.parse(value)
199
+ rescue JSON::ParserError => json_error
200
+ msg = "Unparseable value '#{value}' for --input #{input_name}.\n"
201
+ msg += "When treated as YAML, error: #{yaml_error.message}\n"
202
+ msg += "When treated as JSON, error: #{json_error.message}"
203
+ Inspec::Log.warn msg
204
+ end
205
+ end
206
+ end
207
+ value
208
+ end
209
+
178
210
  def bind_inputs_from_runner_api(profile_name, input_hash)
179
211
  # TODO: move this into a core plugin
180
212
 
@@ -1,6 +1,7 @@
1
1
  require "stringio"
2
2
  require "json"
3
3
  require "inspec/globals"
4
+ require "inspec/config"
4
5
 
5
6
  module Inspec
6
7
  module Deprecation
@@ -32,6 +33,7 @@ module Inspec
32
33
  @groups = {}
33
34
  @unknown_group_action = :warn
34
35
  validate!
36
+ silence_deprecations_from_cli
35
37
  end
36
38
 
37
39
  private
@@ -45,6 +47,25 @@ module Inspec
45
47
  File.open(default_path)
46
48
  end
47
49
 
50
+ def silence_deprecations_from_cli
51
+ # Read --silence-deprecations CLI option
52
+ cfg = Inspec::Config.cached
53
+ return unless cfg[:silence_deprecations]
54
+
55
+ groups_to_silence = cfg[:silence_deprecations]
56
+ silence_all = groups_to_silence.include?("all")
57
+
58
+ groups.each do |group_name, group|
59
+ # Only silence things that warn. Don't silence things that exit;
60
+ # those harsher measures are usually protecting removed code and ignoring
61
+ # and continuing regardless would be perilous and lead to errors.
62
+ if %i{warn fail_control}.include?(group.action) &&
63
+ (silence_all || groups_to_silence.include?(group_name.to_s))
64
+ group.action = :ignore
65
+ end
66
+ end
67
+ end
68
+
48
69
  #====================================================================================================#
49
70
  # Validation
50
71
  #====================================================================================================#
@@ -1,3 +1,3 @@
1
1
  module Inspec
2
- VERSION = "4.19.2".freeze
2
+ VERSION = "4.20.2".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.19.2
4
+ version: 4.20.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef InSpec Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-04 00:00:00.000000000 Z
11
+ date: 2020-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-telemetry