Class: StackMaster::SnsTopicFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/stack_master/sns_topic_finder.rb

Constant Summary collapse

TopicNotFound =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(region) ⇒ SnsTopicFinder

Returns a new instance of SnsTopicFinder.



5
6
7
# File 'lib/stack_master/sns_topic_finder.rb', line 5

def initialize(region)
  @resource = Aws::SNS::Resource.new(region: region)
end

Instance Method Details

#find(reference) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
# File 'lib/stack_master/sns_topic_finder.rb', line 9

def find(reference)
  raise ArgumentError, 'SNS topic references must be non-empty strings' unless reference.is_a?(String) && !reference.empty?

  topic = @resource.topics.detect { |t| topic_name_from_arn(t.arn) == reference }

  raise TopicNotFound, "No topic with name #{reference} found" unless topic

  topic.arn
end