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

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

Instance Method Summary collapse

Methods included from AwsServices

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

Methods included from AwsServices::Util

#find_stack, #rollback_complete?, #stack_exists?, #testing_update?

Methods included from DiffViewer

#diff_viewer, #show_diff

Methods inherited from Base

#build_files, #build_scripts, #capabilities, #check_files, #check_for_errors, #command_with_iam, #continue_update_rollback, #continue_update_rollback_sure?, #delete_rollback_stack, #ensure_s3_bucket_exist, #exit_unless_updatable!, #generate_all, #generate_templates, #initialize, #param_generator, #post_process_templates, #pretty_path, #prompt_for_iam, #quit, #rerun_with_iam?, #set_template_body!, #show_parameters, #stack_status, #starting_message, #status, #tags, #upload_files, #upload_scripts, #upload_templates

Methods included from Util

#are_you_sure?, #switch_current

Methods included from Suffix

#allow_suffix?, #append_suffix, #random_suffix, #remove_suffix, #stack_name_suffix

Methods included from Lono::Conventions

#template_param_convention

Methods included from Blueprint::Root

#bundler_groups, #find_blueprint_root, #require_bundle_gems, #set_blueprint_root

Constructor Details

This class inherits a constructor from Lono::Cfn::Base

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_paramsObject



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

def generated_params
  params = generate_all
  normalize(params)
end

#new_paramsObject



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

def new_params
  params = optional_params.merge(generated_params)
  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_name)

  generated_params # eager call generated_params so its output is above Parameter Diff Preview
  puts "Parameter Diff Preview:".color(:green)
  if @options[:noop]
    puts "NOOP CloudFormation parameters preview for #{@stack_name} 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_name)
  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