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-2.1.1 lib/jets/resource/permission.rb
jets-2.1.0 lib/jets/resource/permission.rb
jets-2.0.6 lib/jets/resource/permission.rb
jets-2.0.5 lib/jets/resource/permission.rb
jets-2.0.4 lib/jets/resource/permission.rb
jets-2.0.3 lib/jets/resource/permission.rb
jets-2.0.1 lib/jets/resource/permission.rb
jets-2.0.0 lib/jets/resource/permission.rb
jets-1.9.32 lib/jets/resource/permission.rb
jets-1.9.31 lib/jets/resource/permission.rb
jets-1.9.30 lib/jets/resource/permission.rb
jets-1.9.29 lib/jets/resource/permission.rb
jets-1.9.28 lib/jets/resource/permission.rb
jets-1.9.27 lib/jets/resource/permission.rb
jets-1.9.26 lib/jets/resource/permission.rb
jets-1.9.25 lib/jets/resource/permission.rb
jets-1.9.24 lib/jets/resource/permission.rb
jets-1.9.23 lib/jets/resource/permission.rb
jets-1.9.22 lib/jets/resource/permission.rb
jets-1.9.21 lib/jets/resource/permission.rb