2018-02-07 15:48:55 +00:00
|
|
|
class AwsRouteTable < Inspec.resource(1)
|
|
|
|
name 'aws_route_table'
|
|
|
|
desc 'Verifies settings for an AWS Route Table'
|
|
|
|
example "
|
|
|
|
describe aws_route_table do
|
2018-08-09 12:16:03 +00:00
|
|
|
its('route_table_id') { should cmp 'rtb-05462d2278326a79c' }
|
2018-02-07 15:48:55 +00:00
|
|
|
end
|
|
|
|
"
|
2018-02-08 04:26:37 +00:00
|
|
|
supports platform: 'aws'
|
2018-02-07 15:48:55 +00:00
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
include AwsSingularResourceMixin
|
2018-02-07 15:48:55 +00:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
"Route Table #{@route_table_id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :route_table_id, :vpc_id
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_params(raw_params)
|
|
|
|
validated_params = check_resource_param_names(
|
|
|
|
raw_params: raw_params,
|
|
|
|
allowed_params: [:route_table_id],
|
|
|
|
allowed_scalar_name: :route_table_id,
|
|
|
|
allowed_scalar_type: String,
|
|
|
|
)
|
|
|
|
|
2018-03-29 16:50:40 +00:00
|
|
|
if validated_params.key?(:route_table_id) &&
|
2018-08-09 12:16:03 +00:00
|
|
|
validated_params[:route_table_id] !~ /^rtb\-([0-9a-f]{17})|(^rtb\-[0-9a-f]{8})$/
|
2018-03-29 16:50:40 +00:00
|
|
|
raise ArgumentError,
|
|
|
|
'aws_route_table Route Table ID must be in the' \
|
2018-08-09 12:16:03 +00:00
|
|
|
' format "rtb-" followed by 8 or 17 hexadecimal characters.'
|
2018-02-07 15:48:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
validated_params
|
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
def fetch_from_api
|
|
|
|
backend = BackendFactory.create(inspec_runner)
|
2018-02-07 15:48:55 +00:00
|
|
|
|
|
|
|
if @route_table_id.nil?
|
|
|
|
args = nil
|
|
|
|
else
|
|
|
|
args = { filters: [{ name: 'route-table-id', values: [@route_table_id] }] }
|
|
|
|
end
|
|
|
|
|
|
|
|
resp = backend.describe_route_tables(args)
|
|
|
|
routetable = resp.to_h[:route_tables]
|
|
|
|
@exists = !routetable.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
class Backend
|
2018-02-08 04:26:37 +00:00
|
|
|
class AwsClientApi < AwsBackendBase
|
2018-02-07 15:48:55 +00:00
|
|
|
BackendFactory.set_default_backend(self)
|
2018-02-08 04:26:37 +00:00
|
|
|
self.aws_client_class = Aws::EC2::Client
|
2018-02-07 15:48:55 +00:00
|
|
|
|
|
|
|
def describe_route_tables(query)
|
2018-02-08 04:26:37 +00:00
|
|
|
aws_service_client.describe_route_tables(query)
|
2018-02-07 15:48:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|