Sha256: 038e4955835064038091c7dc094b0eed343b997144647d70fef40309fb60081e

Contents?: true

Size: 1.78 KB

Versions: 136

Compression:

Stored size: 1.78 KB

Contents

module Jets::Job::Dsl
  module SnsEvent
    def sns_event(topic_name, props={})
      if topic_name.to_s =~ /generate/
        declare_sns_topic(props.delete(:topic_properties))
        topic_arn = "!Ref {namespace}SnsTopic"
        props.merge!(topic_arn: topic_arn)
        declare_sns_subscription(props)
      elsif topic_name.include?('!Ref') # reference shared resource
        topic_arn = topic_name # contains !Ref
        props.merge!(topic_arn: topic_arn)
        declare_sns_subscription(props)
      else # existing topic: short name or full arn
        topic_arn = full_sns_topic_arn(topic_name)
        props.merge!(topic_arn: topic_arn)
        declare_sns_subscription(props)
      end
    end

    def declare_sns_topic(props={})
      props ||= {} # props.delete(:topic_properties) can be nil
      r = Jets::Resource::Sns::Topic.new(props)
      with_fresh_properties do
        resource(r.definition) # add associated resource immediately
      end
    end

    def declare_sns_topic_policy(props={})
      props ||= {} # options.delete(:topic_policy_properties) can be nil
      r = Jets::Resource::Sns::TopicPolicy.new(props)
      with_fresh_properties do
        resource(r.definition) # add associated resource immediately
      end
    end

    def declare_sns_subscription(props={})
      r = Jets::Resource::Sns::Subscription.new(props)
      with_fresh_properties do
        resource(r.definition) # add associated resource immediately
      end
    end

    # Expands simple topic name to full arn. Example:
    #
    #   hello-topic
    # To:
    #   arn:aws:sns:us-west-2:112233445566:hello-topic
    def full_sns_topic_arn(topic_name)
      return topic_name if topic_name.include?("arn:aws:sns")

      "arn:aws:sns:#{Jets.aws.region}:#{Jets.aws.account}:#{topic_name}"
    end
  end
end

Version data entries

136 entries across 136 versions & 3 rubygems

Version Path
jets-4.0.12 lib/jets/job/dsl/sns_event.rb
jets-4.0.11 lib/jets/job/dsl/sns_event.rb
jets-4.0.10 lib/jets/job/dsl/sns_event.rb
jets-4.0.9 lib/jets/job/dsl/sns_event.rb
jets-4.0.8 lib/jets/job/dsl/sns_event.rb
jets-4.0.7 lib/jets/job/dsl/sns_event.rb
jets-4.0.6 lib/jets/job/dsl/sns_event.rb
jets-4.0.5 lib/jets/job/dsl/sns_event.rb
jets-4.0.4 lib/jets/job/dsl/sns_event.rb
jets-4.0.3 lib/jets/job/dsl/sns_event.rb
jets-4.0.2 lib/jets/job/dsl/sns_event.rb
jets-4.0.1 lib/jets/job/dsl/sns_event.rb
jets-4.0.0 lib/jets/job/dsl/sns_event.rb
jets-3.2.2 lib/jets/job/dsl/sns_event.rb
jets-3.2.1 lib/jets/job/dsl/sns_event.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/job/dsl/sns_event.rb
jets-3.2.0 lib/jets/job/dsl/sns_event.rb
jets-3.1.5 lib/jets/job/dsl/sns_event.rb
jets-3.1.4 lib/jets/job/dsl/sns_event.rb
jets-3.1.3 lib/jets/job/dsl/sns_event.rb