Class: Jets::Resource::Iam::Policy

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

Instance Method Summary collapse

Methods inherited from Base

#replacements, #resource

Constructor Details

#initialize(role) ⇒ Policy

Returns a new instance of Policy.



3
4
5
# File 'lib/jets/resource/iam/policy.rb', line 3

def initialize(role)
  @role = role
end

Instance Method Details

#definitionObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jets/resource/iam/policy.rb', line 12

def definition
  logical_id = policy_logical_id

  # Do not assign pretty role_name because long controller names might hit the 64-char
  # limit. Also, IAM roles are global, so assigning role names prevents cross region deploys.
  definition = {
    logical_id => {
      type: "AWS::IAM::Policy",
      properties: {
        roles: [Ref: role_logical_id.camelize],
        policy_name: "#{policy_name[0..127]}", # required, limited to 128-chars
        policy_document: policy_document,
      }
    }
  }

  definition
end

#policy_logical_idObject



8
9
10
# File 'lib/jets/resource/iam/policy.rb', line 8

def policy_logical_id
  role_logical_id.sub(/role$/, "policy")
end