2018-01-18 15:51:06 +00:00
|
|
|
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
|
|
|
|
'
|
2018-02-08 04:26:37 +00:00
|
|
|
supports platform: 'aws'
|
|
|
|
|
|
|
|
include AwsPluralResourceMixin
|
2018-01-18 15:51:06 +00:00
|
|
|
|
|
|
|
# Underlying FilterTable implementation.
|
|
|
|
filter = FilterTable.create
|
2018-06-26 19:14:21 +00:00
|
|
|
filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
|
|
|
filter.register_column(:cidr_blocks, field: :cidr_block)
|
|
|
|
.register_column(:vpc_ids, field: :vpc_id)
|
2018-04-12 19:48:55 +00:00
|
|
|
# We need a dummy here, so FilterTable will define and populate the dhcp_options_id field
|
2018-06-26 19:14:21 +00:00
|
|
|
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)
|
2018-01-18 15:51:06 +00:00
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
def validate_params(raw_params)
|
|
|
|
# No params yet
|
|
|
|
unless raw_params.empty?
|
|
|
|
raise ArgumentError, 'aws_vpcs does not accept resource parameters'
|
|
|
|
end
|
|
|
|
raw_params
|
2018-01-18 15:51:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
'VPCs'
|
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
def fetch_from_api
|
2018-04-12 19:48:55 +00:00
|
|
|
describe_vpcs_response = BackendFactory.create(inspec_runner).describe_vpcs
|
|
|
|
@table = describe_vpcs_response.to_h[:vpcs].map(&:to_h)
|
2018-01-18 15:51:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class Backend
|
2018-02-08 04:26:37 +00:00
|
|
|
class AwsClientApi < AwsBackendBase
|
2018-01-18 15:51:06 +00:00
|
|
|
BackendFactory.set_default_backend(self)
|
2018-02-08 04:26:37 +00:00
|
|
|
self.aws_client_class = Aws::EC2::Client
|
2018-01-18 15:51:06 +00:00
|
|
|
|
|
|
|
def describe_vpcs(query = {})
|
2018-02-08 04:26:37 +00:00
|
|
|
aws_service_client.describe_vpcs(query)
|
2018-01-18 15:51:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|