mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
CFINSPEC-137: Deprecate --target-id option
Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
parent
a658bac10d
commit
8e85e2005b
7 changed files with 52 additions and 51 deletions
|
@ -122,6 +122,10 @@
|
|||
"action": "warn",
|
||||
"prefix": "The --hook option is being replaced by the --activator option.",
|
||||
"suffix": "This options will be removed in InSpec 4.0."
|
||||
},
|
||||
"cli_option_target_id":{
|
||||
"action": "warn",
|
||||
"prefix": "The --target-id option is deprecated in InSpec 5. Its value will be ignored."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ module Inspec
|
|||
option :insecure, type: :boolean, default: false,
|
||||
desc: "Disable SSL verification on select targets"
|
||||
option :target_id, type: :string,
|
||||
desc: "Provide a ID which will be included on reports"
|
||||
desc: "Provide a ID which will be included on reports - deprecated"
|
||||
option :winrm_shell_type, type: :string, default: "powershell",
|
||||
desc: "Specify a shell type for winrm (eg. 'elevated' or 'powershell')"
|
||||
option :docker_url, type: :string,
|
||||
|
|
|
@ -302,6 +302,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|||
def exec(*targets)
|
||||
o = config
|
||||
diagnose(o)
|
||||
deprecate_target_id(config)
|
||||
configure_logger(o)
|
||||
|
||||
runner = Inspec::Runner.new(o)
|
||||
|
@ -320,6 +321,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|||
option :format, type: :string
|
||||
def detect
|
||||
o = config
|
||||
deprecate_target_id(config)
|
||||
o[:command] = "platform.params"
|
||||
|
||||
configure_logger(o)
|
||||
|
@ -360,6 +362,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|||
desc: "Specify one or more inputs directly on the command line to the shell, as --input NAME=VALUE. Accepts single-quoted YAML and JSON structures."
|
||||
def shell_func
|
||||
o = config
|
||||
deprecate_target_id(config)
|
||||
diagnose(o)
|
||||
o[:debug_shell] = true
|
||||
|
||||
|
@ -447,6 +450,12 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|||
|
||||
private
|
||||
|
||||
def deprecate_target_id(config)
|
||||
unless config[:target_id].nil?
|
||||
Inspec.deprecate "cli_option_target_id"
|
||||
end
|
||||
end
|
||||
|
||||
def run_command(opts)
|
||||
runner = Inspec::Runner.new(Inspec::Config.new(opts))
|
||||
res = runner.eval_with_virtual_profile(opts[:command])
|
||||
|
|
|
@ -76,7 +76,7 @@ module Inspec::Reporters
|
|||
}
|
||||
header["Failure Message"] = profile[:status_message] if profile[:status] == "failed"
|
||||
header["Target"] = run_data[:platform][:target] unless run_data[:platform][:target].nil?
|
||||
header["Target ID"] = @config["target_id"] unless @config["target_id"].nil?
|
||||
header["Target ID"] = run_data[:platform][:target_id] || @config["target_id"]# unless @config["target_id"].nil?
|
||||
|
||||
pad = header.keys.max_by(&:length).length + 1
|
||||
header.each do |title, value|
|
||||
|
|
|
@ -210,7 +210,14 @@ module FunctionalHelper
|
|||
|
||||
if opts[:json] && !run_result.stdout.empty?
|
||||
begin
|
||||
@json = JSON.parse(run_result.stdout)
|
||||
out = run_result.stdout.split("\n")
|
||||
if out.count > 1
|
||||
@deprication_msg = out[1].include?("The --target-id option is deprecated in InSpec 5") ? out[0] : nil
|
||||
out = out[1]
|
||||
else
|
||||
out = out[0]
|
||||
end
|
||||
@json = JSON.parse(out)
|
||||
rescue JSON::ParserError => e
|
||||
warn "JSON PARSE ERROR: %s" % [e.message]
|
||||
warn "OUT: <<%s>>" % [run_result.stdout]
|
||||
|
|
|
@ -49,7 +49,8 @@ describe "inspec exec with json formatter" do
|
|||
it "can execute a profile and validate the json schema and override the tagret id with platform uuid" do
|
||||
skip_windows!
|
||||
out = inspec("exec " + complete_profile + " --reporter json --no-create-lockfile --target-id 1d3e399f-4d71-4863-ac54-84d437fbc444")
|
||||
data = JSON.parse(out.stdout)
|
||||
_(out.stdout).must_include "The --target-id option is deprecated in InSpec 5. Its value will be ignored"
|
||||
data = JSON.parse(out.stdout.split("\n")[1])
|
||||
_(data["platform"]["target_id"]).wont_equal "1d3e399f-4d71-4863-ac54-84d437fbc444"
|
||||
_(data["platform"]["target_id"]).must_equal platform_uuid
|
||||
sout = inspec("schema exec-json")
|
||||
|
|
|
@ -59,15 +59,11 @@ describe "inspec exec" do
|
|||
it "executes a minimum metadata-only profile" do
|
||||
inspec("exec " + File.join(profile_path, "simple-metadata") + " --no-create-lockfile")
|
||||
|
||||
_(stdout).must_equal "
|
||||
Profile: yumyum profile
|
||||
Version: (not specified)
|
||||
Target: local://
|
||||
|
||||
No tests executed.
|
||||
|
||||
Test Summary: 0 successful, 0 failures, 0 skipped
|
||||
"
|
||||
_(stdout).must_include "Profile: yumyum profile"
|
||||
_(stdout).must_include "Version: (not specified)"
|
||||
_(stdout).must_include "Target: local://"
|
||||
_(stdout).must_include "No tests executed."
|
||||
_(stdout).must_include "Test Summary: 0 successful, 0 failures, 0 skipped"
|
||||
_(stderr).must_equal ""
|
||||
|
||||
assert_exit_code 0, out
|
||||
|
@ -115,10 +111,11 @@ Test Summary: 0 successful, 0 failures, 0 skipped
|
|||
assert_exit_code 0, out
|
||||
end
|
||||
|
||||
it "can execute the profile with a target_id passthrough" do
|
||||
it "can execute the profile with a target_id passthrough and overrides the --target-id with platform uuid" do
|
||||
skip_windows!
|
||||
inspec("exec #{complete_profile} --no-create-lockfile --target-id 1d3e399f-4d71-4863-ac54-84d437fbc444")
|
||||
|
||||
_(stdout).must_include "Target ID: 1d3e399f-4d71-4863-ac54-84d437fbc444"
|
||||
_(stdout).must_include "Target ID: #{inspec_os_uuid}"
|
||||
|
||||
_(stderr).must_equal ""
|
||||
|
||||
|
@ -127,17 +124,11 @@ Test Summary: 0 successful, 0 failures, 0 skipped
|
|||
|
||||
it "executes a metadata-only profile" do
|
||||
inspec("exec " + File.join(profile_path, "complete-metadata") + " --no-create-lockfile")
|
||||
|
||||
_(stdout).must_equal "
|
||||
Profile: title (name)
|
||||
Version: 1.2.3
|
||||
Target: local://
|
||||
|
||||
No tests executed.
|
||||
|
||||
Test Summary: 0 successful, 0 failures, 0 skipped
|
||||
"
|
||||
|
||||
_(stdout).must_include "Profile: title (name)"
|
||||
_(stdout).must_include "Target: local://"
|
||||
_(stdout).must_include "Version: 1.2.3"
|
||||
_(stdout).must_include "No tests executed."
|
||||
_(stdout).must_include "Test Summary: 0 successful, 0 failures, 0 skipped\n"
|
||||
_(stderr).must_equal ""
|
||||
|
||||
assert_exit_code 0, out
|
||||
|
@ -155,7 +146,7 @@ Test Summary: 0 successful, 0 failures, 0 skipped
|
|||
|
||||
it "executes a specs-only profile" do
|
||||
inspec("exec " + File.join(profile_path, "spec_only") + " --no-create-lockfile")
|
||||
_(stdout).must_include "Target: local://"
|
||||
_(stdout).must_include "Target: local://"
|
||||
_(stdout).must_include "working"
|
||||
_(stdout).must_include "✔ is expected to eq \"working\""
|
||||
_(stdout).must_include "skippy\n"
|
||||
|
@ -528,17 +519,12 @@ Test Summary: 0 successful, 0 failures, 0 skipped
|
|||
describe "with a profile that inherits core resource into custom reosuce" do
|
||||
let(:out) { inspec("exec " + File.join(profile_path, "custom-resource-inheritance") + " --no-create-lockfile") }
|
||||
it "executes the custom resoruc without error" do
|
||||
_(stdout).must_equal "
|
||||
Profile: InSpec Profile (custom-resource-inheritance)
|
||||
Version: 0.1.0
|
||||
Target: local://
|
||||
|
||||
Node Json
|
||||
✔ name is expected to eq \"hello\"
|
||||
✔ [\"meta\", \"creator\"] is expected to eq \"John Doe\"
|
||||
|
||||
Test Summary: 2 successful, 0 failures, 0 skipped
|
||||
"
|
||||
_(stdout).must_include "Profile: InSpec Profile (custom-resource-inheritance)"
|
||||
_(stdout).must_include "Version: 0.1.0"
|
||||
_(stdout).must_include "local://"
|
||||
_(stdout).must_include "✔ name is expected to eq \"hello\""
|
||||
_(stdout).must_include "✔ [\"meta\", \"creator\"] is expected to eq \"John Doe\""
|
||||
_(stdout).must_include "Test Summary: 2 successful, 0 failures, 0 skipped"
|
||||
_(stderr).must_equal ""
|
||||
assert_exit_code 0, out
|
||||
end
|
||||
|
@ -548,19 +534,13 @@ Test Summary: 2 successful, 0 failures, 0 skipped
|
|||
let(:out) { inspec("exec " + example_control + " --no-create-lockfile") }
|
||||
|
||||
it "prints the control results, then the anonymous describe block results" do
|
||||
_(stdout).must_match(/Profile: tests from .*test.fixtures.profiles.old-examples.profile.controls.example-tmp.rb/)
|
||||
_(stdout).must_include "
|
||||
Version: (not specified)
|
||||
Target: local://
|
||||
|
||||
\xE2\x9C\x94 tmp-1.0: Create / directory
|
||||
\xE2\x9C\x94 File / is expected to be directory
|
||||
|
||||
File /
|
||||
\xE2\x9C\x94 is expected to be directory
|
||||
|
||||
Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
|
||||
Test Summary: 2 successful, 0 failures, 0 skipped\n"
|
||||
_(stdout).must_include("test.fixtures.profiles.old-examples.profile.controls.example-tmp.rb")
|
||||
_(stdout).must_include "Version: (not specified)"
|
||||
_(stdout).must_include "Target: local://"
|
||||
_(stdout).must_include "✔ tmp-1.0: Create / directory"
|
||||
_(stdout).must_include "✔ File / is expected to be directory"
|
||||
_(stdout).must_include "Profile Summary: 1 successful control, 0 control failures, 0 controls skipped"
|
||||
_(stdout).must_include "Test Summary: 2 successful, 0 failures, 0 skipped\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue