2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws/aws_plural_resource_mixin"
|
|
|
|
require "resource_support/aws/aws_backend_base"
|
|
|
|
require "aws-sdk-ec2"
|
2019-05-25 08:33:26 +00:00
|
|
|
|
2018-01-18 15:51:06 +00:00
|
|
|
class AwsVpcs < Inspec.resource(1)
|
2019-06-11 22:24:35 +00:00
|
|
|
name "aws_vpcs"
|
|
|
|
desc "Verifies settings for AWS VPCs in bulk"
|
2019-03-19 14:17:32 +00:00
|
|
|
example <<~EXAMPLE
|
2018-01-18 15:51:06 +00:00
|
|
|
describe aws_vpcs do
|
|
|
|
it { should exist }
|
|
|
|
end
|
2019-03-19 14:17:32 +00:00
|
|
|
EXAMPLE
|
2019-06-11 22:24:35 +00:00
|
|
|
supports platform: "aws"
|
2018-02-08 04:26:37 +00:00
|
|
|
|
|
|
|
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)
|
2019-07-09 00:20:30 +00:00
|
|
|
.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)
|
2019-07-09 00:20:30 +00:00
|
|
|
.register_column(:dhcp_options_ids) { |obj| obj.entries.map(&:dhcp_options_id).uniq }
|
2018-06-26 19:14:21 +00:00
|
|
|
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?
|
2019-06-11 22:24:35 +00:00
|
|
|
raise ArgumentError, "aws_vpcs does not accept resource parameters"
|
2018-02-08 04:26:37 +00:00
|
|
|
end
|
2019-07-09 00:20:30 +00:00
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
raw_params
|
2018-01-18 15:51:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2019-06-11 22:24:35 +00:00
|
|
|
"VPCs"
|
2018-01-18 15:51:06 +00:00
|
|
|
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
|