2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws/aws_singular_resource_mixin"
|
|
|
|
require "resource_support/aws/aws_backend_base"
|
|
|
|
require "aws-sdk-sns"
|
2019-05-25 08:33:26 +00:00
|
|
|
|
2018-03-22 17:38:40 +00:00
|
|
|
class AwsSnsSubscription < Inspec.resource(1)
|
2019-06-11 22:24:35 +00:00
|
|
|
name "aws_sns_subscription"
|
|
|
|
desc "Verifies settings for an SNS Subscription"
|
2019-03-19 14:17:32 +00:00
|
|
|
example <<~EXAMPLE
|
2018-03-22 17:38:40 +00:00
|
|
|
describe aws_sns_subscription('arn:aws:sns:us-east-1::test-topic-01:b214aff5-a2c7-438f-a753-8494493f2ff6') do
|
|
|
|
it { should_not have_raw_message_delivery }
|
|
|
|
it { should be_confirmation_authenticated }
|
|
|
|
its('owner') { should cmp '12345678' }
|
|
|
|
its('topic_arn') { should cmp 'arn:aws:sns:us-east-1::test-topic-01' }
|
|
|
|
its('endpoint') { should cmp 'arn:aws:sqs:us-east-1::test-queue-01' }
|
|
|
|
its('protocol') { should cmp 'sqs' }
|
|
|
|
end
|
2019-03-19 14:17:32 +00:00
|
|
|
EXAMPLE
|
2018-03-22 17:38:40 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
supports platform: "aws"
|
2018-03-22 17:38:40 +00:00
|
|
|
|
|
|
|
include AwsSingularResourceMixin
|
|
|
|
attr_reader :arn, :owner, :raw_message_delivery, :topic_arn, :endpoint, :protocol,
|
2019-11-07 23:17:22 +00:00
|
|
|
:confirmation_was_authenticated, :aws_response
|
2018-03-22 17:38:40 +00:00
|
|
|
|
|
|
|
alias confirmation_authenticated? confirmation_was_authenticated
|
|
|
|
alias raw_message_delivery? raw_message_delivery
|
|
|
|
|
|
|
|
def has_raw_message_delivery?
|
|
|
|
raw_message_delivery
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"SNS Subscription #{@arn}"
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_params(raw_params)
|
|
|
|
validated_params = check_resource_param_names(
|
|
|
|
raw_params: raw_params,
|
|
|
|
allowed_params: [:subscription_arn],
|
|
|
|
allowed_scalar_name: :subscription_arn,
|
2019-06-11 22:24:35 +00:00
|
|
|
allowed_scalar_type: String
|
2018-03-22 17:38:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if validated_params.empty?
|
2019-06-11 22:24:35 +00:00
|
|
|
raise ArgumentError, "You must provide a subscription_arn to aws_sns_subscription."
|
2018-03-22 17:38:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
validated_params
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_from_api
|
|
|
|
backend = BackendFactory.create(inspec_runner)
|
|
|
|
catch_aws_errors do
|
|
|
|
begin
|
|
|
|
aws_response = backend.get_subscription_attributes(subscription_arn: @subscription_arn).attributes
|
|
|
|
@exists = true
|
2019-06-11 22:24:35 +00:00
|
|
|
@owner = aws_response["Owner"]
|
|
|
|
@raw_message_delivery = aws_response["RawMessageDelivery"].eql?("true")
|
|
|
|
@topic_arn = aws_response["TopicArn"]
|
|
|
|
@endpoint = aws_response["Endpoint"]
|
|
|
|
@protocol = aws_response["Protocol"]
|
|
|
|
@confirmation_was_authenticated = aws_response["ConfirmationWasAuthenticated"].eql?("true")
|
2018-03-22 17:38:40 +00:00
|
|
|
rescue Aws::SNS::Errors::NotFound
|
|
|
|
@exists = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Backend
|
|
|
|
class AwsClientApi < AwsBackendBase
|
|
|
|
BackendFactory.set_default_backend self
|
|
|
|
self.aws_client_class = Aws::SNS::Client
|
|
|
|
|
|
|
|
def get_subscription_attributes(criteria)
|
|
|
|
aws_service_client.get_subscription_attributes(criteria)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|