Skip to content

Commit

Permalink
Merge de2ebba into 9d7b651
Browse files Browse the repository at this point in the history
  • Loading branch information
zenspider committed Jun 19, 2019
2 parents 9d7b651 + de2ebba commit 28dc705
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
11 changes: 7 additions & 4 deletions lib/inspec/plugin/v1/plugin_types/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,14 @@ def initialize(backend, name, *args)
@__resource_name__ = name

# check resource supports
supported = true
supported = check_supports unless @supports.nil?
supported = @supports ? check_supports : true
test_backend = defined?(Train::Transports::Mock::Connection) && backend.backend.class == Train::Transports::Mock::Connection
# do not return if we are supported, or for tests
return unless supported || test_backend
# raise unless we are supported or in test
unless supported || test_backend
msg = "Unsupported resource/backend combination: %s / %s. Exiting." %
[name, backend.platform.name]
raise ArgumentError, msg
end

# call the resource initializer
begin
Expand Down
29 changes: 16 additions & 13 deletions lib/inspec/resources/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,22 @@ def supported?(supports)
return true if supports.nil? || supports.empty?

status = true
supports.each do |s|
s.each do |k, v|
if %i{os_family os-family platform_family platform-family}.include?(k)
status = in_family?(v)
elsif %i{os platform}.include?(k)
status = platform?(v)
elsif %i{os_name os-name platform_name platform-name}.include?(k)
status = name == v
elsif k == :release
status = check_release(v)
else
status = false
end
supports.each do |support|
support.each do |k, v|
status =
case k
when :os_family, :"os-family", :platform_family, :"platform-family" then
in_family?(v)
when :os, :platform then
platform?(v)
when :os_name, :"os-name", :platform_name, :"platform-name" then
name == v
when :release then
check_release(v)
else
false
end

break if status == false
end
return true if status == true
Expand Down
6 changes: 3 additions & 3 deletions test/functional/inspec_exec_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@
let(:stdout) { out.stdout.force_encoding(Encoding::UTF_8) }
it "exits with an error" do
skip if ENV["NO_AWS"]
stdout.must_include "Resource `aws_iam_users` is not supported on platform"
stdout.must_include "Resource `aws_iam_access_keys` is not supported on platform"
stdout.must_include "Resource `aws_s3_bucket` is not supported on platform"
stdout.must_include "Unsupported resource/backend combination: aws_iam_users"
stdout.must_include "Unsupported resource/backend combination: aws_iam_access_keys"
stdout.must_include "Unsupported resource/backend combination: aws_s3_bucket"
stdout.must_include "3 failures"
out.exit_status.must_equal 100
end
Expand Down

0 comments on commit 28dc705

Please sign in to comment.