lono 5.3.2 → 5.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e0639e6b23ecef2ac642cafdf9f9c9eaeb3dbfdc5cec7d4f7bcfc35068060fe
4
- data.tar.gz: b22af994e3793c5548b14e1203120c46534c84e10d96df56d8e642773ddbbe30
3
+ metadata.gz: e7dbb4bce7dacd00dd7ee37ce9335cb0b8b351bb9bba768f01a7663c09dc4ce0
4
+ data.tar.gz: e41da1e4fca3c854c6b0c8debe9374ca0d3a2e592234cdc24b2306df6e6ae84b
5
5
  SHA512:
6
- metadata.gz: 2b60894c2b295b58cfc80e0f293ad7925a8152dbe2bb5e794481d97a658c270c2c1f7160601e2a274fcab5109cd9bbbcf72a4d90c088fd85197a82da17cd3fd6
7
- data.tar.gz: 49badaca98ef867ae2e9503057f9f7d14c3d1ae72ae6750665a13bfc061d833c6b3195c41c3c3d7a2f798a00f72c389d55d71515995087a1872f424b3acf496d
6
+ metadata.gz: a51d6207cd16a08628750e1f4169e04964d09cc9d3dbd6e3bf4b8ea8d6404863c840f61b6658b2ceedafaadb0c447a7ad1d78e6c6a896afe533747e662db1df6
7
+ data.tar.gz: bcdd52effdeec486e452db25c91108cfaa2aa24fc7bb9042e2f82af2aae6a77d4f3d58b50c52a80c7693083c047055bf3445b54b17ef06d077ce158c49e2e51a
data/CHANGELOG.md CHANGED
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [5.3.3]
7
+ - #12 fix param preview
8
+
6
9
  ## [5.3.2]
7
10
  - #11 enable sse-s3 encryption for lono managed s3 bucket
8
11
 
@@ -9,37 +9,56 @@ module Lono::Cfn::Preview
9
9
  def run
10
10
  return unless stack_exists?(@stack_name)
11
11
 
12
+ generated_params # eager call generated_params so its output is above Parameter Diff Preview
12
13
  puts "Parameter Diff Preview:".color(:green)
13
14
  if @options[:noop]
14
15
  puts "NOOP CloudFormation parameters preview for #{@stack_name} update"
15
16
  return
16
17
  end
17
18
 
18
- write_to_tmp(existing_path, existing_parameters)
19
- write_to_tmp(new_path, new_parameters)
19
+ write_to_tmp(existing_path, existing_params)
20
+ write_to_tmp(new_path, new_params)
20
21
 
21
22
  show_diff(existing_path, new_path)
22
23
  end
23
24
 
24
- def new_parameters
25
+ def existing_params
26
+ existing = stack_parameters
27
+ params = normalize(existing)
28
+ subtract(params, noecho_params)
29
+ end
30
+ memoize :existing_params
31
+
32
+ def new_params
33
+ params = optional_params.merge(generated_params)
34
+ subtract(params, noecho_params)
35
+ end
36
+
37
+ def subtract(h1,h2)
38
+ hash = h1.reject do |k,v|
39
+ h2[k] == v
40
+ end
41
+ Hash[hash.sort_by {|k,v| k}]
42
+ end
43
+
44
+ def generated_params
25
45
  params = generate_all
26
- params.reject { |p| ignore_parameters.include?(p[:parameter_key]) }
46
+ normalize(params)
27
47
  end
48
+ memoize :generated_params
28
49
 
29
- def existing_parameters
30
- existing = stack_parameters
31
- existing = existing.reject { |p| ignore_parameters.include?(p.parameter_key) }
32
- convert_to_cfn_format(existing)
50
+ def optional_params
51
+ # normalizing to simple Hash
52
+ optional_parameters.inject({}) do |result,(k,v)|
53
+ result.merge(k => v["Default"].to_s)
54
+ end
33
55
  end
34
56
 
35
- def ignore_parameters
36
- # Remove optional parameters if they match already. Produces better diff.
37
- optional = optional_parameters.map { |logical_id, attributes| logical_id }
57
+ def noecho_params
38
58
  noecho = stack_parameters.select { |p| p.parameter_value == '****' }
39
- noecho = noecho.map { |p| p.parameter_key }
40
- optional + noecho
59
+ normalize(noecho)
41
60
  end
42
- memoize :ignore_parameters
61
+ memoize :noecho_params
43
62
 
44
63
  def stack_parameters
45
64
  resp = cfn.describe_stacks(stack_name: @stack_name)
@@ -54,18 +73,25 @@ module Lono::Cfn::Preview
54
73
  end
55
74
  memoize :output_template
56
75
 
57
- def write_to_tmp(path, list)
58
- converted = convert_to_cfn_format(list)
59
- text = JSON.pretty_generate(converted)
76
+ def write_to_tmp(path, hash)
77
+ text = JSON.pretty_generate(hash)
60
78
  FileUtils.mkdir_p(File.dirname(path))
61
79
  IO.write(path, text)
62
80
  end
63
81
 
64
- def convert_to_cfn_format(list)
82
+
83
+ # Returns simple Hash. Example:
84
+ #
85
+ # {"foo"=>"1", "bar"=>"2"},
86
+ #
87
+ def normalize(list)
65
88
  camelized = list.map(&:to_h).map do |h|
66
89
  h.transform_keys {|k| k.to_s.camelize}
67
90
  end
68
- camelized.sort_by { |h| h["ParameterKey"] }
91
+ camelized.sort_by! { |h| h["ParameterKey"] }
92
+ camelized.inject({}) do |result,h|
93
+ result.merge(h["ParameterKey"] => h["ParameterValue"])
94
+ end
69
95
  end
70
96
 
71
97
  def existing_path
data/lib/lono/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lono
2
- VERSION = "5.3.2"
2
+ VERSION = "5.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lono
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.2
4
+ version: 5.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-24 00:00:00.000000000 Z
11
+ date: 2019-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport