mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
8683c54510
* Search and replace filtertable methods to use new names, and rely on automatic methods * Remove spurious exists? matchers - see https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/exist-matcher * Revert removing exists? - we'll do it on a separate PR * Gah, didn't save before resolving conflict * Add back name column on aws cloudtrail trails Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
50 lines
1.4 KiB
Ruby
50 lines
1.4 KiB
Ruby
class AwsVpcs < Inspec.resource(1)
|
|
name 'aws_vpcs'
|
|
desc 'Verifies settings for AWS VPCs in bulk'
|
|
example '
|
|
describe aws_vpcs do
|
|
it { should exist }
|
|
end
|
|
'
|
|
supports platform: 'aws'
|
|
|
|
include AwsPluralResourceMixin
|
|
|
|
# Underlying FilterTable implementation.
|
|
filter = FilterTable.create
|
|
filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
|
filter.register_column(:cidr_blocks, field: :cidr_block)
|
|
.register_column(:vpc_ids, field: :vpc_id)
|
|
# We need a dummy here, so FilterTable will define and populate the dhcp_options_id field
|
|
filter.register_column(:dummy, field: :dhcp_options_id)
|
|
.register_column(:dhcp_options_ids) { |obj| obj.entries.map(&:dhcp_options_id).uniq }
|
|
filter.install_filter_methods_on_resource(self, :table)
|
|
|
|
def validate_params(raw_params)
|
|
# No params yet
|
|
unless raw_params.empty?
|
|
raise ArgumentError, 'aws_vpcs does not accept resource parameters'
|
|
end
|
|
raw_params
|
|
end
|
|
|
|
def to_s
|
|
'VPCs'
|
|
end
|
|
|
|
def fetch_from_api
|
|
describe_vpcs_response = BackendFactory.create(inspec_runner).describe_vpcs
|
|
@table = describe_vpcs_response.to_h[:vpcs].map(&:to_h)
|
|
end
|
|
|
|
class Backend
|
|
class AwsClientApi < AwsBackendBase
|
|
BackendFactory.set_default_backend(self)
|
|
self.aws_client_class = Aws::EC2::Client
|
|
|
|
def describe_vpcs(query = {})
|
|
aws_service_client.describe_vpcs(query)
|
|
end
|
|
end
|
|
end
|
|
end
|