stack_master 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 365c8c1252350564177ff9a0827024d27a7600f31c7a76503cac20accfca5e12
4
- data.tar.gz: '088c89fe1880f1879279b66b8eb26d59e6ec723ec842c81641f7e20f457aefb7'
3
+ metadata.gz: 6b2fd9ecb9882d2a0b00adee84d08975f5ae51b72297a449c5bd5218efbf8a17
4
+ data.tar.gz: c2eb23ba0ae38e6db17cc296a4a151aaaf7785bbff222d75ec671251ac398f1f
5
5
  SHA512:
6
- metadata.gz: 6488da7b3d7ad2562e276246f76f2ec304c9b83c43d24469a76ccde609da290c648ac417232e42864b163dbb1b3111a06052322a8ba9037626eef7f0feb956ab
7
- data.tar.gz: 0f7006a2c2f37f25e771727be69a5823407163ed9ac6a7970ea95a3a8ce07c25fc4f150c9a6fce46c0e5dae9219516699afd095962fdb08f745770a36eccea78
6
+ metadata.gz: e5832578334d932b9750b9aa2914c6c0fc9d2b391606c3ab8fc60868b151c5b9fa996d2b89636d14515aff3b9892c8a913c1e0531ac57262a67072931a2a8f1c
7
+ data.tar.gz: 87dd2728b566b6d775a0b8cb7137acc856f1ee854436e35789578c1c129798594375bc9ad06018be2285605878918cf89d872c3df72fe20a3260380407e32b25
data/README.md CHANGED
@@ -157,14 +157,12 @@ template_compilers:
157
157
 
158
158
  Parameters are loaded from multiple YAML files, merged from the following lookup paths from bottom to top:
159
159
 
160
- - parameters/[underscored_stack_name].yaml
161
- - parameters/[underscored_stack_name].yml
162
- - parameters/[region]/[underscored_stack_name].yaml
163
- - parameters/[region]/[underscored_stack_name].yml
164
- - parameters/[region_alias]/[underscored_stack_name].yaml
165
- - parameters/[region_alias]/[underscored_stack_name].yml
166
-
167
- **Note:** The file names must be underscored, not hyphenated, even if the stack names are hyphenated.
160
+ - parameters/[stack_name].yaml
161
+ - parameters/[stack_name].yml
162
+ - parameters/[region]/[stack_name].yaml
163
+ - parameters/[region]/[stack_name].yml
164
+ - parameters/[region_alias]/[stack_name].yaml
165
+ - parameters/[region_alias]/[stack_name].yml
168
166
 
169
167
  A simple parameter file could look like this:
170
168
 
data/bin/stack_master CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
3
  require 'stack_master'
5
4
 
6
5
  if ENV['STUB_AWS'] == 'true'
data/lib/stack_master.rb CHANGED
@@ -8,7 +8,9 @@ require 'aws-sdk-s3'
8
8
  require 'aws-sdk-sns'
9
9
  require 'aws-sdk-ssm'
10
10
  require 'colorize'
11
- require 'active_support/core_ext/string'
11
+ require 'active_support/core_ext/hash/keys'
12
+ require 'active_support/core_ext/object/blank'
13
+ require 'active_support/core_ext/string/inflections'
12
14
  require 'multi_json'
13
15
 
14
16
  MultiJson.use :json_gem
@@ -71,7 +71,7 @@ module StackMaster
71
71
  unless args.size == 2
72
72
  say "Invalid arguments. stack_master init [region] [stack_name]"
73
73
  else
74
- StackMaster::Commands::Init.perform(options.overwrite, *args)
74
+ StackMaster::Commands::Init.perform(options, *args)
75
75
  end
76
76
  end
77
77
  end
@@ -119,7 +119,7 @@ module StackMaster
119
119
  options.defaults config: default_config_file
120
120
  say "Invalid arguments." if args.size > 0
121
121
  config = load_config(options.config)
122
- StackMaster::Commands::ListStacks.perform(config)
122
+ StackMaster::Commands::ListStacks.perform(config, nil, options)
123
123
  end
124
124
  end
125
125
 
@@ -165,7 +165,7 @@ module StackMaster
165
165
  options.defaults config: default_config_file
166
166
  say "Invalid arguments. stack_master status" and return unless args.size == 0
167
167
  config = load_config(options.config)
168
- StackMaster::Commands::Status.perform(config)
168
+ StackMaster::Commands::Status.perform(config, nil, options)
169
169
  end
170
170
  end
171
171
 
@@ -178,7 +178,7 @@ module StackMaster
178
178
  options.defaults config: default_config_file
179
179
  say "Invalid arguments. stack_master tidy" and return unless args.size == 0
180
180
  config = load_config(options.config)
181
- StackMaster::Commands::Tidy.perform(config)
181
+ StackMaster::Commands::Tidy.perform(config, nil, options)
182
182
  end
183
183
  end
184
184
 
@@ -208,7 +208,7 @@ module StackMaster
208
208
 
209
209
  success = execute_if_allowed_account(allowed_accounts) do
210
210
  StackMaster.cloud_formation_driver.set_region(region)
211
- StackMaster::Commands::Delete.perform(region, stack_name).success?
211
+ StackMaster::Commands::Delete.perform(region, stack_name, options).success?
212
212
  end
213
213
  @kernel.exit false unless success
214
214
  end
@@ -27,6 +27,12 @@ module StackMaster
27
27
  end
28
28
  end
29
29
 
30
+ def initialize(config, stack_definition = nil, options = Commander::Command::Options.new)
31
+ @config = config
32
+ @stack_definition = stack_definition
33
+ @options = options
34
+ end
35
+
30
36
  def success?
31
37
  @failed != true
32
38
  end
@@ -36,9 +42,24 @@ module StackMaster
36
42
  def error_message(e)
37
43
  msg = "#{e.class} #{e.message}"
38
44
  msg << "\n Caused by: #{e.cause.class} #{e.cause.message}" if e.cause
45
+ if options.trace
46
+ msg << "\n#{backtrace(e)}"
47
+ else
48
+ msg << "\n Use --trace to view backtrace"
49
+ end
39
50
  msg
40
51
  end
41
52
 
53
+ def backtrace(error)
54
+ if error.respond_to?(:full_message)
55
+ error.full_message
56
+ else
57
+ # full_message was introduced in Ruby 2.5
58
+ # remove this conditional when StackMaster no longer supports Ruby 2.4
59
+ error.backtrace.join("\n")
60
+ end
61
+ end
62
+
42
63
  def failed(message = nil)
43
64
  StackMaster.stderr.puts(message) if message
44
65
  @failed = true
@@ -53,5 +74,9 @@ module StackMaster
53
74
  StackMaster.stdout.puts(message) if message
54
75
  throw :halt
55
76
  end
77
+
78
+ def options
79
+ @options ||= Commander::Command::Options.new
80
+ end
56
81
  end
57
82
  end
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module StackMaster
2
4
  module Commands
3
5
  class Apply
@@ -6,14 +8,10 @@ module StackMaster
6
8
  include StackMaster::Prompter
7
9
  TEMPLATE_TOO_LARGE_ERROR_MESSAGE = 'The (space compressed) stack is larger than the limit set by AWS. See http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html'.freeze
8
10
 
9
- def initialize(config, stack_definition, options = Commander::Command::Options.new)
10
- @config = config
11
- @s3_config = stack_definition.s3
12
- @stack_definition = stack_definition
11
+ def initialize(*_args)
12
+ super
13
+ @s3_config = @stack_definition.s3
13
14
  @from_time = Time.now
14
- @options = options
15
- @options.on_failure ||= nil
16
- @options.yes_param ||= nil
17
15
  end
18
16
 
19
17
  def perform
@@ -208,11 +206,16 @@ module StackMaster
208
206
 
209
207
  def ensure_valid_parameters!
210
208
  if @proposed_stack.missing_parameters?
211
- StackMaster.stderr.puts "Empty/blank parameters detected, ensure values exist for those parameters. Parameters will be read from the following locations:"
212
- @stack_definition.parameter_files.each do |parameter_file|
213
- StackMaster.stderr.puts " - #{parameter_file}"
209
+ message = <<~MESSAGE
210
+ Empty/blank parameters detected, ensure values exist for those parameters.
211
+ Parameters will be read from the following locations:
212
+ MESSAGE
213
+ base_dir = Pathname.new(@stack_definition.base_dir)
214
+ @stack_definition.parameter_file_globs.each do |glob|
215
+ parameter_file = Pathname.new(glob).relative_path_from(base_dir)
216
+ message << " - #{parameter_file}\n"
214
217
  end
215
- halt!
218
+ failed!(message)
216
219
  end
217
220
  end
218
221
 
@@ -4,11 +4,6 @@ module StackMaster
4
4
  include Command
5
5
  include Commander::UI
6
6
 
7
- def initialize(config, stack_definition, options = {})
8
- @config = config
9
- @stack_definition = stack_definition
10
- end
11
-
12
7
  def perform
13
8
  puts(proposed_stack.template_body)
14
9
  end
@@ -4,7 +4,8 @@ module StackMaster
4
4
  include Command
5
5
  include StackMaster::Prompter
6
6
 
7
- def initialize(region, stack_name)
7
+ def initialize(region, stack_name, options)
8
+ super(nil, nil, options)
8
9
  @region = region
9
10
  @stack_name = stack_name
10
11
  @from_time = Time.now
@@ -4,11 +4,6 @@ module StackMaster
4
4
  include Command
5
5
  include Commander::UI
6
6
 
7
- def initialize(config, stack_definition, options = {})
8
- @config = config
9
- @stack_definition = stack_definition
10
- end
11
-
12
7
  def perform
13
8
  StackMaster::StackDiffer.new(proposed_stack, stack).output_diff
14
9
  end
@@ -4,12 +4,6 @@ module StackMaster
4
4
  include Command
5
5
  include Commander::UI
6
6
 
7
- def initialize(config, stack_definition, options = {})
8
- @config = config
9
- @stack_definition = stack_definition
10
- @options = options
11
- end
12
-
13
7
  def perform
14
8
  events = StackEvents::Fetcher.fetch(@stack_definition.stack_name, @stack_definition.region)
15
9
  filter_events(events).each do |event|
@@ -5,8 +5,8 @@ module StackMaster
5
5
  class Init
6
6
  include Command
7
7
 
8
- def initialize(overwrite, region, stack_name)
9
- @overwrite = overwrite
8
+ def initialize(options, region, stack_name)
9
+ super(nil, nil, options)
10
10
  @region = region
11
11
  @stack_name = stack_name
12
12
  end
@@ -24,10 +24,10 @@ module StackMaster
24
24
  def check_files
25
25
  @stack_master_filename = "stack_master.yml"
26
26
  @stack_json_filename = "templates/#{@stack_name}.json"
27
- @parameters_filename = File.join("parameters", "#{underscored_stack_name}.yml")
28
- @region_parameters_filename = File.join("parameters", @region, "#{underscored_stack_name}.yml")
27
+ @parameters_filename = File.join("parameters", "#{@stack_name}.yml")
28
+ @region_parameters_filename = File.join("parameters", @region, "#{@stack_name}.yml")
29
29
 
30
- if !@overwrite
30
+ if !@options.overwrite
31
31
  [@stack_master_filename, @stack_json_filename, @parameters_filename, @region_parameters_filename].each do |filename|
32
32
  if File.exists?(filename)
33
33
  StackMaster.stderr.puts("Aborting: #{filename} already exists. Use --overwrite to force overwriting file.")
@@ -89,10 +89,6 @@ module StackMaster
89
89
  File.join(StackMaster.base_dir, "stacktemplates", "parameter_region.yml")
90
90
  end
91
91
 
92
- def underscored_stack_name
93
- @stack_name.gsub('-', '_')
94
- end
95
-
96
92
  def render(renderer)
97
93
  binding = InitBinding.new(region: @region, stack_name: @stack_name).get_binding
98
94
  renderer.result(binding)
@@ -6,11 +6,6 @@ module StackMaster
6
6
  include Command
7
7
  include Commander::UI
8
8
 
9
- def initialize(config, stack_definition, options = {})
10
- @config = config
11
- @stack_definition = stack_definition
12
- end
13
-
14
9
  def perform
15
10
  unless cfn_lint_available
16
11
  failed! 'Failed to run cfn-lint. You may need to install it using'\
@@ -7,10 +7,6 @@ module StackMaster
7
7
  include Commander::UI
8
8
  include StackMaster::Commands::TerminalHelper
9
9
 
10
- def initialize(config)
11
- @config = config
12
- end
13
-
14
10
  def perform
15
11
  tp.set :max_width, self.window_size
16
12
  tp @config.stacks, :region, :stack_name
@@ -7,11 +7,6 @@ module StackMaster
7
7
  include Commander::UI
8
8
  include StackMaster::Commands::TerminalHelper
9
9
 
10
- def initialize(config, stack_definition, options = {})
11
- @config = config
12
- @stack_definition = stack_definition
13
- end
14
-
15
10
  def perform
16
11
  if stack
17
12
  tp.set :max_width, self.window_size
@@ -6,11 +6,6 @@ module StackMaster
6
6
  include Command
7
7
  include Commander::UI
8
8
 
9
- def initialize(config, stack_definition, options = {})
10
- @config = config
11
- @stack_definition = stack_definition
12
- end
13
-
14
9
  def perform
15
10
  if stack_resources
16
11
  tp stack_resources, :logical_resource_id, :resource_type, :timestamp, :resource_status, :resource_status_reason, :description
@@ -7,8 +7,8 @@ module StackMaster
7
7
  include Command
8
8
  include StackMaster::Commands::TerminalHelper
9
9
 
10
- def initialize(config, show_progress = true)
11
- @config = config
10
+ def initialize(config, options, show_progress = true)
11
+ super(config, nil, options)
12
12
  @show_progress = show_progress
13
13
  end
14
14
 
@@ -4,10 +4,6 @@ module StackMaster
4
4
  include Command
5
5
  include StackMaster::Commands::TerminalHelper
6
6
 
7
- def initialize(config)
8
- @config = config
9
- end
10
-
11
7
  def perform
12
8
  used_templates = []
13
9
  used_parameter_files = []
@@ -4,11 +4,6 @@ module StackMaster
4
4
  include Command
5
5
  include Commander::UI
6
6
 
7
- def initialize(config, stack_definition, options = {})
8
- @config = config
9
- @stack_definition = stack_definition
10
- end
11
-
12
7
  def perform
13
8
  failed unless Validator.valid?(@stack_definition, @config)
14
9
  end
@@ -12,7 +12,7 @@ module StackMaster
12
12
  owners = Array(value.fetch('owners', 'self').to_s)
13
13
  ami_finder = AmiFinder.new(@stack_definition.region)
14
14
  filters = ami_finder.build_filters_from_hash(value.fetch('filters'))
15
- ami_finder.find_latest_ami(filters, owners).try(:image_id)
15
+ ami_finder.find_latest_ami(filters, owners)&.image_id
16
16
  end
17
17
  end
18
18
  end
@@ -11,7 +11,7 @@ module StackMaster
11
11
 
12
12
  def resolve(value)
13
13
  filters = @ami_finder.build_filters_from_string(value, prefix = "tag")
14
- @ami_finder.find_latest_ami(filters).try(:image_id)
14
+ @ami_finder.find_latest_ami(filters)&.image_id
15
15
  end
16
16
  end
17
17
  end
@@ -71,7 +71,7 @@ module StackMaster
71
71
  newlines = lines.split("\n").map do |line|
72
72
  "#{line}#{newlines.pop}"
73
73
  end
74
- if lines.starts_with?("\n")
74
+ if lines.start_with?("\n")
75
75
  newlines.insert(0, "\n")
76
76
  end
77
77
  newlines
@@ -23,7 +23,6 @@ module StackMaster
23
23
  include Utils::Initializable
24
24
 
25
25
  def initialize(attributes = {})
26
- @additional_parameter_lookup_dirs = []
27
26
  @compiler_options = {}
28
27
  @notification_arns = []
29
28
  @s3 = {}
@@ -32,6 +31,7 @@ module StackMaster
32
31
  @ejson_file_kms = true
33
32
  @compiler = nil
34
33
  super
34
+ @additional_parameter_lookup_dirs ||= []
35
35
  @template_dir ||= File.join(@base_dir, 'templates')
36
36
  @allowed_accounts = Array(@allowed_accounts)
37
37
  end
@@ -86,7 +86,11 @@ module StackMaster
86
86
  end
87
87
 
88
88
  def parameter_files
89
- [ default_parameter_file_path, region_parameter_file_path, additional_parameter_lookup_file_paths ].flatten.compact
89
+ parameter_file_globs.map(&Dir.method(:glob)).flatten
90
+ end
91
+
92
+ def parameter_file_globs
93
+ [ default_parameter_glob, region_parameter_glob ] + additional_parameter_lookup_globs
90
94
  end
91
95
 
92
96
  def stack_policy_file_path
@@ -99,23 +103,22 @@ module StackMaster
99
103
 
100
104
  private
101
105
 
102
- def additional_parameter_lookup_file_paths
103
- return unless additional_parameter_lookup_dirs
106
+ def additional_parameter_lookup_globs
104
107
  additional_parameter_lookup_dirs.map do |a|
105
- Dir.glob(File.join(base_dir, 'parameters', a, "#{underscored_stack_name}.y*ml"))
108
+ File.join(base_dir, 'parameters', a, "#{stack_name_glob}.y*ml")
106
109
  end
107
110
  end
108
111
 
109
- def region_parameter_file_path
110
- Dir.glob(File.join(base_dir, 'parameters', "#{region}", "#{underscored_stack_name}.y*ml"))
112
+ def region_parameter_glob
113
+ File.join(base_dir, 'parameters', "#{region}", "#{stack_name_glob}.y*ml")
111
114
  end
112
115
 
113
- def default_parameter_file_path
114
- Dir.glob(File.join(base_dir, 'parameters', "#{underscored_stack_name}.y*ml"))
116
+ def default_parameter_glob
117
+ File.join(base_dir, 'parameters', "#{stack_name_glob}.y*ml")
115
118
  end
116
119
 
117
- def underscored_stack_name
118
- stack_name.gsub('-', '_')
120
+ def stack_name_glob
121
+ stack_name.gsub('-', '[-_]')
119
122
  end
120
123
  end
121
124
  end
@@ -11,7 +11,7 @@ module StackMaster
11
11
  compiler.require_dependencies
12
12
  compiler.compile(template_dir, template, compile_time_parameters, compiler_options)
13
13
  rescue StandardError => e
14
- raise TemplateCompilationFailed.new("Failed to compile #{template} with error #{e}.\n#{e.backtrace}")
14
+ raise TemplateCompilationFailed, "Failed to compile #{template}"
15
15
  end
16
16
 
17
17
  def self.register(name, klass)
@@ -1,3 +1,3 @@
1
1
  module StackMaster
2
- VERSION = "2.2.0"
2
+ VERSION = "2.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Hodgkiss
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-03-13 00:00:00.000000000 Z
12
+ date: 2020-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -523,8 +523,8 @@ licenses:
523
523
  metadata:
524
524
  bug_tracker_uri: https://github.com/envato/stack_master/issues
525
525
  changelog_uri: https://github.com/envato/stack_master/blob/master/CHANGELOG.md
526
- documentation_uri: https://www.rubydoc.info/gems/stack_master/2.2.0
527
- source_code_uri: https://github.com/envato/stack_master/tree/v2.2.0
526
+ documentation_uri: https://www.rubydoc.info/gems/stack_master/2.3.0
527
+ source_code_uri: https://github.com/envato/stack_master/tree/v2.3.0
528
528
  post_install_message:
529
529
  rdoc_options: []
530
530
  require_paths:
@@ -540,7 +540,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
540
540
  - !ruby/object:Gem::Version
541
541
  version: '0'
542
542
  requirements: []
543
- rubygems_version: 3.0.4
543
+ rubygems_version: 3.1.2
544
544
  signing_key:
545
545
  specification_version: 4
546
546
  summary: StackMaster is a sure-footed way of creating, updating and keeping track