Sha256: 69ec07159c6c7acde02728dd212762f972c948f5c76b1b13261f8e3466bec9fd

Contents?: true

Size: 1.5 KB

Versions: 150

Compression:

Stored size: 1.5 KB

Contents

module Jets::Resource::Iam
  class FunctionRole < Jets::Resource::Base
    include BaseRoleDefinition

    def initialize(task)
      @task = task
      @policy_definitions = task.iam_policy || [] # iam_policy contains policy definitions
      @managed_policy_definitions = task.managed_iam_policy || [] # managed_iam_policy contains policy definitions
    end

    def role_logical_id
      "{namespace}_iam_role".underscore
    end

    def policy_name
      funcion_namespace = replacements[:namespace].underscore.dasherize
      "#{Jets.config.project_namespace}-#{funcion_namespace}-policy" # camelized because used as template value
    end

    def replacements
      {
        namespace: "#{@task.class_name.gsub('::','')}#{@task.meth.to_s.camelize}", # camelized because can be used as value
      }
    end

    def policy_document
      if inherit?
        @policy_definitions += class_role.policy_definitions + application_role.policy_definitions
      end
      super
    end

    def managed_policy_arns
      if inherit?
        @managed_policy_definitions += class_role.managed_policy_definitions + application_role.managed_policy_definitions
      end
      super
    end

    def inherit?
      !@policy_definitions.empty? || !@managed_policy_definitions.empty?
    end

    def class_role
      Jets::Resource::Iam::ClassRole.new(@task.class_name.constantize)
    end
    memoize :class_role

    def application_role
      Jets::Resource::Iam::ApplicationRole.new
    end
    memoize :application_role
  end
end

Version data entries

150 entries across 150 versions & 4 rubygems

Version Path
jets-1.6.9 lib/jets/resource/iam/function_role.rb
jets-1.6.8 lib/jets/resource/iam/function_role.rb
jets-1.6.7 lib/jets/resource/iam/function_role.rb
jets-1.6.6 lib/jets/resource/iam/function_role.rb
jets-1.6.5 lib/jets/resource/iam/function_role.rb
jets-1.6.4 lib/jets/resource/iam/function_role.rb
jets-1.6.3 lib/jets/resource/iam/function_role.rb
jets-1.6.2 lib/jets/resource/iam/function_role.rb
jets-1.6.1 lib/jets/resource/iam/function_role.rb
jets-1.6.0 lib/jets/resource/iam/function_role.rb