Class: Jets::Resource::Iam::FunctionRole

Inherits:
Base
  • Object
show all
Includes:
BaseRoleDefinition
Defined in:
lib/jets/resource/iam/function_role.rb

Instance Attribute Summary

Attributes included from BaseRoleDefinition

#managed_policy_definitions, #policy_definitions

Instance Method Summary collapse

Methods included from BaseRoleDefinition

#definition

Methods inherited from Base

#resource

Constructor Details

#initialize(task) ⇒ FunctionRole

Returns a new instance of FunctionRole.



5
6
7
8
9
# File 'lib/jets/resource/iam/function_role.rb', line 5

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

Instance Method Details

#application_roleObject



49
50
51
# File 'lib/jets/resource/iam/function_role.rb', line 49

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

#class_roleObject



44
45
46
# File 'lib/jets/resource/iam/function_role.rb', line 44

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

#inherit?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/jets/resource/iam/function_role.rb', line 40

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

#managed_policy_arnsObject



33
34
35
36
37
38
# File 'lib/jets/resource/iam/function_role.rb', line 33

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

#policy_documentObject



26
27
28
29
30
31
# File 'lib/jets/resource/iam/function_role.rb', line 26

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

#policy_nameObject



15
16
17
18
# File 'lib/jets/resource/iam/function_role.rb', line 15

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

#replacementsObject



20
21
22
23
24
# File 'lib/jets/resource/iam/function_role.rb', line 20

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

#role_logical_idObject



11
12
13
# File 'lib/jets/resource/iam/function_role.rb', line 11

def role_logical_id
  "{namespace}_iam_role".underscore
end