2017-11-16 18:44:43 +00:00
|
|
|
class AwsSnsTopic < Inspec.resource(1)
|
|
|
|
name 'aws_sns_topic'
|
|
|
|
desc 'Verifies settings for an SNS Topic'
|
2019-03-19 14:17:32 +00:00
|
|
|
example <<~EXAMPLE
|
2017-11-16 18:44:43 +00:00
|
|
|
describe aws_sns_topic('arn:aws:sns:us-east-1:123456789012:some-topic') do
|
|
|
|
it { should exist }
|
|
|
|
its('confirmed_subscription_count') { should_not be_zero }
|
|
|
|
end
|
2019-03-19 14:17:32 +00:00
|
|
|
EXAMPLE
|
2018-02-08 04:26:37 +00:00
|
|
|
supports platform: 'aws'
|
2017-11-16 18:44:43 +00:00
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
include AwsSingularResourceMixin
|
2017-11-16 18:44:43 +00:00
|
|
|
attr_reader :arn, :confirmed_subscription_count
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_params(raw_params)
|
2017-12-04 18:32:13 +00:00
|
|
|
validated_params = check_resource_param_names(
|
|
|
|
raw_params: raw_params,
|
|
|
|
allowed_params: [:arn],
|
|
|
|
allowed_scalar_name: :arn,
|
|
|
|
allowed_scalar_type: String,
|
|
|
|
)
|
2017-11-16 18:44:43 +00:00
|
|
|
# Validate the ARN
|
|
|
|
unless validated_params[:arn] =~ /^arn:aws:sns:[\w\-]+:\d{12}:[\S]+$/
|
|
|
|
raise ArgumentError, 'Malformed ARN for SNS topics. Expected an ARN of the form ' \
|
|
|
|
"'arn:aws:sns:REGION:ACCOUNT-ID:TOPIC-NAME'"
|
|
|
|
end
|
|
|
|
validated_params
|
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
def fetch_from_api
|
|
|
|
aws_response = BackendFactory.create(inspec_runner).get_topic_attributes(topic_arn: @arn).attributes
|
2017-11-16 18:44:43 +00:00
|
|
|
@exists = true
|
|
|
|
|
|
|
|
# The response has a plain hash with CamelCase plain string keys and string values
|
|
|
|
@confirmed_subscription_count = aws_response['SubscriptionsConfirmed'].to_i
|
|
|
|
rescue Aws::SNS::Errors::NotFound
|
|
|
|
@exists = false
|
|
|
|
end
|
|
|
|
|
2017-12-04 18:32:13 +00:00
|
|
|
# Uses the SDK API to really talk to AWS
|
2017-11-16 18:44:43 +00:00
|
|
|
class Backend
|
2018-02-08 04:26:37 +00:00
|
|
|
class AwsClientApi < AwsBackendBase
|
2017-12-04 18:32:13 +00:00
|
|
|
BackendFactory.set_default_backend(self)
|
2018-02-08 04:26:37 +00:00
|
|
|
self.aws_client_class = Aws::SNS::Client
|
2017-11-16 18:44:43 +00:00
|
|
|
|
|
|
|
def get_topic_attributes(criteria)
|
2018-02-08 04:26:37 +00:00
|
|
|
aws_service_client.get_topic_attributes(criteria)
|
2017-11-16 18:44:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|