Class: Sfn::Callback::StackPolicy
- Inherits:
-
Sfn::Callback
- Object
- Sfn::Callback
- Sfn::Callback::StackPolicy
- Defined in:
- lib/sfn/callback/stack_policy.rb
Constant Summary collapse
- DEFENSELESS_POLICY =
Policy to apply prior to stack deletion
{ 'Statement' => [{ 'Effect' => 'Allow', 'Action' => 'Update:*', 'Resource' => '*', 'Principal' => '*' }] }
Instance Attribute Summary collapse
-
#policies ⇒ Smash
readonly
Cached policies.
Attributes inherited from Sfn::Callback
#api, #arguments, #config, #ui
Instance Method Summary collapse
-
#before_update(args) ⇒ Object
Disable all existing policies prior to update.
-
#initialize(*args) ⇒ self
constructor
Overload to init policy cache.
-
#save_stack_policy(p_stack) ⇒ NilClass
Save the cached policy for the given stack.
-
#submit_policy(args) ⇒ Object
(also: #after_create, #after_update)
Submit all cached policies.
-
#template(info) ⇒ Object
Generate stack policy for stack and cache for the after hook to handle.
Methods inherited from Sfn::Callback
Constructor Details
#initialize(*args) ⇒ self
Overload to init policy cache
23 24 25 26 |
# File 'lib/sfn/callback/stack_policy.rb', line 23 def initialize(*args) super @policies = Smash.new end |
Instance Attribute Details
#policies ⇒ Smash (readonly)
Returns cached policies.
18 19 20 |
# File 'lib/sfn/callback/stack_policy.rb', line 18 def policies @policies end |
Instance Method Details
#before_update(args) ⇒ Object
Disable all existing policies prior to update
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sfn/callback/stack_policy.rb', line 47 def before_update(args) if(config.get(:stack_policy, :update).to_s == 'defenseless') ui.warn 'Disabling all stack policies for update.' stack = args[:api_stack] ([stack] + stack.nested_stacks).compact.each do |p_stack| @policies[p_stack.name] = DEFENSELESS_POLICY run_action "Disabling stack policy for #{ui.color(p_stack.name, :yellow)}" do save_stack_policy(p_stack) end end end end |
#save_stack_policy(p_stack) ⇒ NilClass
Save the cached policy for the given stack
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sfn/callback/stack_policy.rb', line 76 def save_stack_policy(p_stack) result = p_stack.api.request( :path => '/', :method => :post, :form => Smash.new( 'Action' => 'SetStackPolicy', 'StackName' => p_stack.id, 'StackPolicyBody' => MultiJson.dump( @policies.fetch(p_stack.id, @policies.fetch(p_stack.data[:logical_id], @policies[p_stack.name] ) ) ) ) ) end |
#submit_policy(args) ⇒ Object Also known as: after_create, after_update
Submit all cached policies
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sfn/callback/stack_policy.rb', line 31 def submit_policy(args) ui.info 'Submitting stack policy documents' stack = args[:api_stack] ([stack] + stack.nested_stacks).compact.each do |p_stack| run_action "Applying stack policy to #{ui.color(p_stack.name, :yellow)}" do save_stack_policy(p_stack) end end ui.info 'Stack policy documents successfully submitted!' end |
#template(info) ⇒ Object
Generate stack policy for stack and cache for the after hook to handle
64 65 66 67 68 69 70 |
# File 'lib/sfn/callback/stack_policy.rb', line 64 def template(info) if(info[:sparkle_stack]) @policies.set(info[:stack_name], info[:sparkle_stack].generate_policy ) end end |