mirror of
https://github.com/inspec/inspec
synced 2024-12-11 22:02:47 +00:00
2857d07151
The opening and closing mechanic varied between all the various resources. This changes them all to use a HEREDOC with a tilde to remove leading whitespace. This removes the need for the special method to trim the `#print_example` method from shell. Signed-off-by: Franklin Webber <franklin.webber@gmail.com>
55 lines
1.3 KiB
Ruby
55 lines
1.3 KiB
Ruby
class AwsIamRole < Inspec.resource(1)
|
|
name 'aws_iam_role'
|
|
desc 'Verifies settings for an IAM Role'
|
|
example <<~EXAMPLE
|
|
describe aws_iam_role('my-role') do
|
|
it { should exist }
|
|
end
|
|
EXAMPLE
|
|
supports platform: 'aws'
|
|
|
|
include AwsSingularResourceMixin
|
|
attr_reader :description, :role_name
|
|
|
|
def to_s
|
|
"IAM Role #{role_name}"
|
|
end
|
|
|
|
private
|
|
|
|
def validate_params(raw_params)
|
|
validated_params = check_resource_param_names(
|
|
raw_params: raw_params,
|
|
allowed_params: [:role_name],
|
|
allowed_scalar_name: :role_name,
|
|
allowed_scalar_type: String,
|
|
)
|
|
if validated_params.empty?
|
|
raise ArgumentError, 'You must provide a role_name to aws_iam_role.'
|
|
end
|
|
validated_params
|
|
end
|
|
|
|
def fetch_from_api
|
|
role_info = nil
|
|
begin
|
|
role_info = BackendFactory.create(inspec_runner).get_role(role_name: role_name)
|
|
rescue Aws::IAM::Errors::NoSuchEntity
|
|
@exists = false
|
|
return
|
|
end
|
|
@exists = true
|
|
@description = role_info.role.description
|
|
end
|
|
|
|
# Uses the SDK API to really talk to AWS
|
|
class Backend
|
|
class AwsClientApi < AwsBackendBase
|
|
BackendFactory.set_default_backend(self)
|
|
self.aws_client_class = Aws::IAM::Client
|
|
def get_role(query)
|
|
aws_service_client.get_role(query)
|
|
end
|
|
end
|
|
end
|
|
end
|