Sha256: 3bd4f9f0533aa1e294099773489eda23455f5c2c4f8adbe8c07f9906b590c132

Contents?: true

Size: 1.21 KB

Versions: 136

Compression:

Stored size: 1.21 KB

Contents

class Jets::Resource
  class Permission < Jets::Resource::Base
    def initialize(replacements, associated_resource)
      @replacements = replacements
      @associated_resource = associated_resource
    end

    def definition
      logical_id = permission_logical_id

      definition = {
        logical_id => {
          type: "AWS::Lambda::Permission",
          properties: {
            function_name: "!GetAtt {namespace}LambdaFunction.Arn",
            action: "lambda:InvokeFunction",
            principal: principal
          }
        }
      }

      # From AWS docs: https://amzn.to/2N0QXQL
      # source_arn is "not supported by all event sources"
      definition[logical_id][:properties][:source_arn] = source_arn if source_arn

      definition
    end

    def permission_logical_id
      logical_id = "{namespace}_permission"
      md = @associated_resource.logical_id.match(/(\d+)$/)
      counter = md[1] if md
      [logical_id, counter].compact.join('').underscore
    end

    # Auto-detect principal from the associated resources.
    def principal
      Replacer.principal_map(@associated_resource.type)
    end

    def source_arn
      Replacer.source_arn_map(@associated_resource.type)
    end
  end
end

Version data entries

136 entries across 136 versions & 3 rubygems

Version Path
jets-1.9.0 lib/jets/resource/permission.rb
jets-1.8.14 lib/jets/resource/permission.rb
jets-1.8.13 lib/jets/resource/permission.rb
jets-1.8.12 lib/jets/resource/permission.rb
jets-1.8.11 lib/jets/resource/permission.rb
jets-1.8.10 lib/jets/resource/permission.rb
jets-1.8.9 lib/jets/resource/permission.rb
jets-1.8.8 lib/jets/resource/permission.rb
jets-1.8.7 lib/jets/resource/permission.rb
jets-1.8.6 lib/jets/resource/permission.rb
jets-1.8.5 lib/jets/resource/permission.rb
jets-1.8.4 lib/jets/resource/permission.rb
jets-1.8.3 lib/jets/resource/permission.rb
jets-1.8.2 lib/jets/resource/permission.rb
jets-1.8.1 lib/jets/resource/permission.rb
jets-1.8.0 lib/jets/resource/permission.rb