Skip to content

Commit

Permalink
Support for AWS SQS queue
Browse files Browse the repository at this point in the history
  • Loading branch information
amitsaha committed Dec 19, 2018
1 parent e6311c4 commit ede17f6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/resource_support/aws.rb
Expand Up @@ -51,6 +51,7 @@
require 'resources/aws/aws_sns_subscription'
require 'resources/aws/aws_sns_topic'
require 'resources/aws/aws_sns_topics'
require 'resources/aws/aws_sqs_queue'
require 'resources/aws/aws_subnet'
require 'resources/aws/aws_subnets'
require 'resources/aws/aws_vpc'
Expand Down
54 changes: 54 additions & 0 deletions lib/resources/aws/aws_sqs_queue.rb
@@ -0,0 +1,54 @@
class AwsSqsQueue < Inspec.resource(1)
name 'aws_sqs_queue'
desc 'Verifies settings for an SQS Queue'
example "
describe aws_sqs_queue('https://sqs.ap-southeast-2.amazonaws.com/519527725796/QueueName') do
it { should exist }
its('confirmed_subscription_count') { should_not be_zero }
end
"
supports platform: 'aws'

include AwsSingularResourceMixin
attr_reader :arn, :visibility_timeout

private

def validate_params(raw_params)
validated_params = check_resource_param_names(
raw_params: raw_params,
allowed_params: [:url],
allowed_scalar_name: :url,
allowed_scalar_type: String,
)
# Validate the URL
# FIXME
#unless validated_params[:url] =~ /^arn:aws:sqs:[\w\-]+:\d{12}:[\S]+$/
# raise ArgumentError, 'Malformed ARN for SQS. Expected an ARN of the form ' \
# "'arn:aws:sqs:REGION:ACCOUNT-ID:QUEUE-NAME'"
#end
validated_params
end

def fetch_from_api
aws_response = BackendFactory.create(inspec_runner).get_queue_attributes(queue_url: @url, attribute_names: ["All"]).attributes
@exists = true

# The response has a plain hash with CamelCase plain string keys and string values
@visibility_timeout = aws_response['VisibilityTimeout'].to_i
rescue Aws::SQS::Errors::NotFound
@exists = false
end

# Uses the SDK API to really talk to AWS
class Backend
class AwsClientApi < AwsBackendBase
BackendFactory.set_default_backend(self)
self.aws_client_class = Aws::SQS::Client

def get_queue_attributes(criteria)
aws_service_client.get_queue_attributes(criteria)
end
end
end
end

0 comments on commit ede17f6

Please sign in to comment.