cloudformation-ruby-dsl 1.2.5 → 1.2.6

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
  SHA1:
3
- metadata.gz: 0c0ff566160bc6cd49546a86129814e4f7456149
4
- data.tar.gz: f2b3e70794460d1214c1c336762f2d4e238b3247
3
+ metadata.gz: fcefa7ca9233df5bfcd9223e6558c2849db7b18c
4
+ data.tar.gz: 9c056b722df8348be8a1932c9374eadd2d71cfa9
5
5
  SHA512:
6
- metadata.gz: 87f36d247b8db1ec5fcbe951f35a84a71d127883185788fc29676d0be65bac0e5f05648ad81f9d4c0f602a0b52b00d52c4c4b958c837f0b0069b1ac42eff1c9b
7
- data.tar.gz: 63de25f85683010039ec5215b41fd05a2e0924b6b69582d691a512c152aff19e98f1f6bbe8950d4580fc68c0eafafc29c03e170c4ccca1d5b76a644a12a17cea
6
+ metadata.gz: a855706d0b535cb20450fe23a47bf3380342c2f15c7b1899c182179b5e09c85b51d1d3e327f44c6f90ba89ccdcea0dd53d264cd628c4c366e469fe60f8c059ae
7
+ data.tar.gz: cb4ab5611b187e4da6923f8312e70c2cdfbcc928dd8fd57b41b3ffa68d9a92439044b94357a37af2a0453d33be77352cc5624abaf08214f4ee3bb0ff12cdae9a
data/README.md CHANGED
@@ -79,6 +79,7 @@ Invoke an intrinsic CloudFormation function.
79
79
  - `join(delim, *list)`
80
80
  - `select(index, list)`
81
81
  - `ref(name)`
82
+ - `import_value(value)`
82
83
 
83
84
  Intrinsic conditionals are also supported, with some syntactic sugar.
84
85
  - `fn_not(condition)`
@@ -78,26 +78,32 @@ end
78
78
 
79
79
  # Parse command-line arguments and return the parameters and region
80
80
  def parse_args
81
- stack_name = nil
82
- parameters = {}
83
- region = default_region
84
- profile = nil
85
- nopretty = false
81
+ args = {
82
+ :stack_name => nil,
83
+ :parameters => {},
84
+ :interactive => false,
85
+ :region => default_region,
86
+ :profile => nil,
87
+ :nopretty => false,
88
+ }
86
89
  ARGV.slice_before(/^--/).each do |name, value|
87
90
  case name
88
91
  when '--stack-name'
89
- stack_name = value
92
+ args[:stack_name] = value
90
93
  when '--parameters'
91
- parameters = Hash[value.split(/;/).map { |pair| pair.split(/=/, 2) }] #/# fix for syntax highlighting
94
+ args[:parameters] = Hash[value.split(/;/).map { |pair| pair.split(/=/, 2) }] #/# fix for syntax highlighting
95
+ when '--interactive'
96
+ args[:interactive] = true
92
97
  when '--region'
93
- region = value
98
+ args[:region] = value
94
99
  when '--profile'
95
- profile = value
100
+ args[:profile] = value
96
101
  when '--nopretty'
97
- nopretty = true
102
+ args[:nopretty] = true
98
103
  end
99
104
  end
100
- [stack_name, parameters, region, profile, nopretty]
105
+
106
+ args
101
107
  end
102
108
 
103
109
  def validate_action(action)
@@ -294,13 +300,16 @@ def cfn(template)
294
300
  template_body: template_string,
295
301
  parameters: template.parameters.map { |k,v| {parameter_key: k, parameter_value: v}}.to_a,
296
302
  tags: cfn_tags.map { |k,v| {"key" => k.to_s, "value" => v} }.to_a,
297
- capabilities: ["CAPABILITY_IAM"],
303
+ capabilities: ["CAPABILITY_NAMED_IAM"],
298
304
  }
299
305
 
300
306
  # fill in options from the command line
301
307
  extra_options = parse_arg_array_as_hash(options)
302
308
  create_stack_opts = extra_options.merge(create_stack_opts)
303
309
 
310
+ # remove custom options
311
+ create_stack_opts.delete(:interactive)
312
+
304
313
  # create stack
305
314
  create_result = cfn_client.create_stack(create_stack_opts)
306
315
  if create_result.successful?
@@ -486,13 +495,16 @@ def cfn(template)
486
495
  template_body: template_string,
487
496
  parameters: template.parameters.map { |k,v| {parameter_key: k, parameter_value: v}}.to_a,
488
497
  tags: cfn_tags.map { |k,v| {"key" => k.to_s, "value" => v.to_s} }.to_a,
489
- capabilities: ["CAPABILITY_IAM"],
498
+ capabilities: ["CAPABILITY_NAMED_IAM"],
490
499
  }
491
500
 
492
501
  # fill in options from the command line
493
502
  extra_options = parse_arg_array_as_hash(options)
494
503
  update_stack_opts = extra_options.merge(update_stack_opts)
495
504
 
505
+ # remove custom options
506
+ update_stack_opts.delete(:interactive)
507
+
496
508
  # update the stack
497
509
  update_result = cfn_client.update_stack(update_stack_opts)
498
510
  if update_result.successful?
@@ -567,6 +579,6 @@ end
567
579
 
568
580
  # Main entry point
569
581
  def template(&block)
570
- stack_name, parameters, aws_region, aws_profile, nopretty = parse_args
571
- raw_template(parameters, stack_name, aws_region, aws_profile, nopretty, &block)
582
+ options = parse_args
583
+ raw_template(options, &block)
572
584
  end
@@ -44,8 +44,8 @@ end
44
44
  ############################# CloudFormation DSL
45
45
 
46
46
  # Main entry point
47
- def raw_template(parameters = {}, stack_name = nil, aws_region = default_region, aws_profile = nil, nopretty = false, &block)
48
- TemplateDSL.new(parameters, stack_name, aws_region, aws_profile, nopretty, &block)
47
+ def raw_template(options, &block)
48
+ TemplateDSL.new(options, &block)
49
49
  end
50
50
 
51
51
  def default_region
@@ -54,14 +54,20 @@ end
54
54
 
55
55
  # Core interpreter for the DSL
56
56
  class TemplateDSL < JsonObjectDSL
57
- attr_reader :parameters, :aws_region, :nopretty, :stack_name, :aws_profile
58
-
59
- def initialize(parameters = {}, stack_name = nil, aws_region = default_region, aws_profile = nil, nopretty = false)
60
- @parameters = parameters
61
- @stack_name = stack_name
62
- @aws_region = aws_region
63
- @aws_profile = aws_profile
64
- @nopretty = nopretty
57
+ attr_reader :parameters,
58
+ :parameter_cli,
59
+ :aws_region,
60
+ :nopretty,
61
+ :stack_name,
62
+ :aws_profile
63
+
64
+ def initialize(options)
65
+ @parameters = options[:parameters]
66
+ @interactive = options[:interactive]
67
+ @stack_name = options[:stack_name]
68
+ @aws_region = options[:region]
69
+ @aws_profile = options[:profile]
70
+ @nopretty = options[:nopretty]
65
71
  super()
66
72
  end
67
73
 
@@ -71,7 +77,12 @@ class TemplateDSL < JsonObjectDSL
71
77
 
72
78
  def parameter(name, options)
73
79
  default(:Parameters, {})[name] = options
74
- @parameters[name] ||= options[:Default]
80
+
81
+ if @interactive
82
+ @parameters[name] ||= _get_parameter_from_cli(name, options)
83
+ else
84
+ @parameters[name] ||= options[:Default]
85
+ end
75
86
  end
76
87
 
77
88
  # Find parameters where the specified attribute is true then remove the attribute from the cfn template.
@@ -162,6 +173,73 @@ class TemplateDSL < JsonObjectDSL
162
173
  { :'Fn::FindInMap' => [ map, key, name ] }
163
174
  end
164
175
  end
176
+
177
+ private
178
+ def _get_parameter_from_cli(name, options)
179
+ # basic request
180
+ param_request = "Parameter '#{name}' (#{options[:Type]})"
181
+
182
+ # add description to request
183
+ if options.has_key?(:Description)
184
+ param_request += "\nDescription: #{options[:Description]}"
185
+ end
186
+
187
+ # add validation to the request
188
+
189
+ # allowed pattern
190
+ if options.has_key?(:AllowedPattern)
191
+ param_request += "\nAllowed Pattern: /#{options[:AllowedPattern]}/"
192
+ end
193
+
194
+ # allowed values
195
+ if options.has_key?(:AllowedValues)
196
+ param_request += "\nAllowed Values: #{options[:AllowedValues].join(', ')}"
197
+ end
198
+
199
+ # min/max length
200
+ if options.has_key?(:MinLength) or options.has_key?(:MaxLength)
201
+ min_length = "-infinity"
202
+ max_length = "+infinity"
203
+ if options.has_key?(:MinLength)
204
+ min_length = options[:MinLength]
205
+ end
206
+ if options.has_key?(:MaxLength)
207
+ max_length = options[:MaxLength]
208
+ end
209
+ param_request += "\nValid Length: #{min_length} < string < #{max_length}"
210
+ end
211
+
212
+ # min/max value
213
+ if options.has_key?(:MinValue) or options.has_key?(:MaxValue)
214
+ min_value = "-infinity"
215
+ max_value = "+infinity"
216
+ if options.has_key?(:MinValue)
217
+ min_value = options[:MinValue]
218
+ end
219
+ if options.has_key?(:MaxValue)
220
+ max_value = options[:MaxValue]
221
+ end
222
+ param_request += "\nValid Number: #{min_value} < number < #{max_value}"
223
+ end
224
+
225
+ # add default to request
226
+ if options.has_key?(:Default) and !options[:Default].nil?
227
+ param_request += "\nLeave value empty for default: #{options[:Default]}"
228
+ end
229
+
230
+ param_request += "\nValue: "
231
+
232
+ # request the param
233
+ $stdout.puts "===================="
234
+ $stdout.print param_request
235
+ input = $stdin.gets.chomp
236
+
237
+ if input.nil? or input.empty?
238
+ options[:Default]
239
+ else
240
+ input
241
+ end
242
+ end
165
243
  end
166
244
 
167
245
  def base64(value) { :'Fn::Base64' => value } end
@@ -172,6 +250,8 @@ def get_att(resource, attribute) { :'Fn::GetAtt' => [ resource, attribute ] } en
172
250
 
173
251
  def get_azs(region = '') { :'Fn::GetAZs' => region } end
174
252
 
253
+ def import_value(value) { :'Fn::ImportValue' => value } end
254
+
175
255
  def join(delim, *list)
176
256
  case list.length
177
257
  when 0 then ''
@@ -15,7 +15,7 @@
15
15
  module Cfn
16
16
  module Ruby
17
17
  module Dsl
18
- VERSION = "1.2.5"
18
+ VERSION = "1.2.6"
19
19
  end
20
20
  end
21
21
  end
@@ -104,7 +104,7 @@ module FileHelpers
104
104
  # Delete a file from the spec/tmp directory
105
105
  def delete_test_file(filename)
106
106
  abs_path = File.join(from_project_root("spec/tmp"), filename)
107
- FileUtils.rm(abs_path)
107
+ FileUtils.rm(abs_path) if File.exist?(abs_path)
108
108
  end
109
109
 
110
110
  ##
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudformation-ruby-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Smith
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2016-10-18 00:00:00.000000000 Z
18
+ date: 2016-11-03 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: detabulator