Class: Jets::Cfn::TemplateBuilders::IamPolicy::BasePolicy
- Inherits:
-
Object
- Object
- Jets::Cfn::TemplateBuilders::IamPolicy::BasePolicy
- Extended by:
- Memoist
- Defined in:
- lib/jets/cfn/template_builders/iam_policy/base_policy.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
Instance Method Summary collapse
-
#classify_name(text) ⇒ Object
Need to underscore and then classify again for this case: Jets::PreheatJob_policy => JetsPreheatJobPolicy Or else you we get this: Jets::PreheatJob_policy => JetsPreheatjobPolicy.
- #policy_document ⇒ Object
-
#setup ⇒ Object
Not using initialize because method signature is different.
- #standardize(definition) ⇒ Object
Instance Attribute Details
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
10 11 12 |
# File 'lib/jets/cfn/template_builders/iam_policy/base_policy.rb', line 10 def definitions @definitions end |
Instance Method Details
#classify_name(text) ⇒ Object
53 54 55 |
# File 'lib/jets/cfn/template_builders/iam_policy/base_policy.rb', line 53 def classify_name(text) text.gsub('::','_').underscore.classify end |
#policy_document ⇒ Object
22 23 24 25 26 |
# File 'lib/jets/cfn/template_builders/iam_policy/base_policy.rb', line 22 def policy_document definitions.map { |definition| standardize(definition) } # Thanks: https://www.mnishiguchi.com/2017/11/29/rails-hash-camelize-and-underscore-keys/ @policy.deep_transform_keys! { |key| key.to_s.camelize } end |
#setup ⇒ Object
Not using initialize because method signature is different
12 13 14 15 16 17 18 19 20 |
# File 'lib/jets/cfn/template_builders/iam_policy/base_policy.rb', line 12 def setup # empty starting policy that will be changed @policy = { "Version" => "2012-10-17", "Statement" => [] } # https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_sid.html @sid = 0 # counter end |
#standardize(definition) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jets/cfn/template_builders/iam_policy/base_policy.rb', line 29 def standardize(definition) @sid += 1 case definition when String @policy["Statement"] << { sid: "Stmt#{@sid}", action: [definition], effect: "Allow", resource: "*", } when Hash definition = definition.stringify_keys if definition.key?("Version") # special case where we replace the policy entirely @policy = definition else @policy["Statement"] << definition end end end |