Class: Lono::Cfn::Preview::Param

Inherits:
Base show all
Includes:
AwsServices, DiffViewer
Defined in:
lib/lono/cfn/preview/param.rb

Direct Known Subclasses

Sets::Preview::Param

Instance Method Summary collapse

Methods included from AwsServices

#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts

Methods included from AwsServices::Helper

#rollback_complete?, #testing_update?

Methods included from AwsServices::StackSet

#find_stack_set, #stack_set_exists?

Methods included from AwsServices::Stack

#find_stack, #stack_exists?

Methods included from DiffViewer

#diff_viewer, #show_diff

Methods inherited from Base

#capabilities, #command_with_iam, #continue_update_rollback, #continue_update_rollback_sure?, #delete_rollback_stack, #exit_unless_updatable!, #generate_all, #notification_arns, #pretty_path, #prompt_for_iam, #quit, #rerun_with_iam?, #set_template_url!, #show_options, #stack_status, #starting_message, #status, #tags

Methods included from Utils::Sure

#sure?

Methods inherited from AbstractBase

#initialize, #reinitialize, #template_path

Methods included from Blueprint::Root

#find_blueprint_root, #set_blueprint_root

Constructor Details

This class inherits a constructor from Lono::AbstractBase

Instance Method Details

#existing_paramsObject



25
26
27
28
29
# File 'lib/lono/cfn/preview/param.rb', line 25

def existing_params
  existing = stack_parameters
  params = normalize(existing)
  subtract(params, noecho_params)
end

#generated_parametersObject



45
46
47
48
# File 'lib/lono/cfn/preview/param.rb', line 45

def generated_parameters
  parameters = generate_all
  normalize(parameters)
end

#new_paramsObject



32
33
34
35
# File 'lib/lono/cfn/preview/param.rb', line 32

def new_params
  params = optional_params.merge(generated_parameters)
  subtract(params, noecho_params)
end

#noecho_paramsObject



58
59
60
61
# File 'lib/lono/cfn/preview/param.rb', line 58

def noecho_params
  noecho = stack_parameters.select { |p| p.parameter_value == '****' }
  normalize(noecho)
end

#optional_paramsObject



51
52
53
54
55
56
# File 'lib/lono/cfn/preview/param.rb', line 51

def optional_params
  # normalizing to simple Hash
  optional_parameters.inject({}) do |result,(k,v)|
    result.merge(k => v["Default"].to_s)
  end
end

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lono/cfn/preview/param.rb', line 9

def run
  return unless stack_exists?(@stack)

  generated_parameters # eager call generated_parameters so its output is above Parameter Diff Preview
  puts "Parameter Diff Preview:".color(:green)
  if @options[:noop]
    puts "NOOP CloudFormation parameters preview for #{@stack} update"
    return
  end

  write_to_tmp(existing_path, existing_params)
  write_to_tmp(new_path, new_params)

  show_diff(existing_path, new_path)
end

#stack_parametersObject



64
65
66
67
68
# File 'lib/lono/cfn/preview/param.rb', line 64

def stack_parameters
  resp = cfn.describe_stacks(stack_name: @stack)
  stack = resp.stacks.first
  stack.parameters
end

#subtract(h1, h2) ⇒ Object

Remove items with the same key. The value can be different. This removes the noecho params.



38
39
40
41
42
43
# File 'lib/lono/cfn/preview/param.rb', line 38

def subtract(h1,h2)
  hash = h1.reject do |k,v|
    h2.keys.include?(k)
  end
  Hash[hash.sort_by {|k,v| k}]
end