Class: Jets::Resource::Iam::ClassRole
- Includes:
- BaseRoleDefinition
- Defined in:
- lib/jets/resource/iam/class_role.rb
Instance Attribute Summary
Attributes included from BaseRoleDefinition
#managed_policy_definitions, #policy_definitions
Instance Method Summary collapse
-
#all_classes ⇒ Object
Class heirachry in top to down order.
- #application_role ⇒ Object
-
#inherit? ⇒ Boolean
There are 2 types of inheritance: from superclasses and from higher precedence policies.
-
#initialize(app_class) ⇒ ClassRole
constructor
A new instance of ClassRole.
-
#lookup_iam_policies ⇒ Object
Accounts for inherited class_iam_policies from superclasses.
-
#lookup_managed_iam_policies ⇒ Object
Accounts for inherited class_managed_iam_policy from superclasses.
- #managed_policy_arns ⇒ Object
- #policy_document ⇒ Object
- #replacements ⇒ Object
- #role_logical_id ⇒ Object
- #role_name ⇒ Object
Methods included from BaseRoleDefinition
Methods inherited from Base
Constructor Details
#initialize(app_class) ⇒ ClassRole
Returns a new instance of ClassRole.
5 6 7 8 9 |
# File 'lib/jets/resource/iam/class_role.rb', line 5 def initialize(app_class) @app_class = app_class.to_s # IE: PostsController, HardJob, Hello, HelloFunction @policy_definitions = lookup_iam_policies @managed_policy_definitions = lookup_managed_iam_policies end |
Instance Method Details
#all_classes ⇒ Object
Class heirachry in top to down order
63 64 65 66 67 68 69 70 71 |
# File 'lib/jets/resource/iam/class_role.rb', line 63 def all_classes klass = @app_class.constantize all_classes = [] while klass != Object all_classes << klass klass = klass.superclass end all_classes.reverse end |
#application_role ⇒ Object
43 44 45 |
# File 'lib/jets/resource/iam/class_role.rb', line 43 def application_role Jets::Resource::Iam::ApplicationRole.new end |
#inherit? ⇒ Boolean
There are 2 types of inheritance: from superclasses and from higher precedence policies. This one manages the inheritance for higher precedence policies.
39 40 41 |
# File 'lib/jets/resource/iam/class_role.rb', line 39 def inherit? !@policy_definitions.empty? || !@managed_policy_definitions.empty? end |
#lookup_iam_policies ⇒ Object
Accounts for inherited class_iam_policies from superclasses
56 57 58 59 60 |
# File 'lib/jets/resource/iam/class_role.rb', line 56 def lookup_iam_policies all_classes.map do |k| k.class_iam_policy # class_iam_policy contains definitions end.uniq end |
#lookup_managed_iam_policies ⇒ Object
Accounts for inherited class_managed_iam_policy from superclasses
49 50 51 52 53 |
# File 'lib/jets/resource/iam/class_role.rb', line 49 def lookup_managed_iam_policies all_classes.map do |k| k.class_managed_iam_policy # class_managed_iam_policy contains definitions end.uniq end |
#managed_policy_arns ⇒ Object
32 33 34 35 |
# File 'lib/jets/resource/iam/class_role.rb', line 32 def managed_policy_arns @managed_policy_definitions += application_role.managed_policy_definitions if inherit? super end |
#policy_document ⇒ Object
26 27 28 29 30 |
# File 'lib/jets/resource/iam/class_role.rb', line 26 def policy_document # Handles precedence inheritance from the ApplicationRole to the ClassRole @policy_definitions += application_role.policy_definitions if inherit? super end |
#replacements ⇒ Object
20 21 22 23 24 |
# File 'lib/jets/resource/iam/class_role.rb', line 20 def replacements { namespace: @app_class.gsub('::','').camelize, # camelized because can be used as value } end |
#role_logical_id ⇒ Object
11 12 13 |
# File 'lib/jets/resource/iam/class_role.rb', line 11 def role_logical_id "{namespace}_iam_role".underscore end |