sparkle_formation 0.2.10 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/sparkle_formation/sparkle_attribute.rb +39 -0
- data/lib/sparkle_formation/sparkle_formation.rb +57 -8
- data/lib/sparkle_formation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46a1c4f04178bc15ec4ebce5da8046a7187bf9cb
|
4
|
+
data.tar.gz: 74608ee05fd93fdcbe70762a0c6702d5a0f2aeb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33caa72fa07477b8c4bd48c6d2da66817fc292bd22f2d6817234673f17b95abd3532d3c6e29a6d4b2776c46e47557b17c33ba6647f2985e97dd8add9b14b3ad2
|
7
|
+
data.tar.gz: 51bf91bef24f3618847f31815be27964aa858203c5e964bee9b66aee32e77e76d290b405b545ac40e7e16d53a7ff37f34819601096ddbb35af6fd07294a67bb5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## v0.2.12
|
2
|
+
* Stubs for template generation parameters
|
3
|
+
* Add `no_value!` helper method
|
4
|
+
* Force path resets with `sparkle_path` is set
|
5
|
+
* Include all missing pseudo parameter helpers
|
6
|
+
* Provide more control on dynamic naming
|
7
|
+
|
1
8
|
## v0.2.10
|
2
9
|
* Add helper for generating no value
|
3
10
|
* Fix Fn::If generator (#35 thanks @yhuang !)
|
@@ -234,6 +234,31 @@ class SparkleFormation
|
|
234
234
|
end
|
235
235
|
alias_method :no_value!, :_no_value
|
236
236
|
|
237
|
+
def _region
|
238
|
+
_ref('AWS::Region')
|
239
|
+
end
|
240
|
+
alias_method :region!, :_region
|
241
|
+
|
242
|
+
def _notification_arns
|
243
|
+
_ref('AWS::NotificationARNs')
|
244
|
+
end
|
245
|
+
alias_method :notification_arns!, :_notification_arns
|
246
|
+
|
247
|
+
def _account_id
|
248
|
+
_ref('AWS::AccountId')
|
249
|
+
end
|
250
|
+
alias_method :account_id!, :_account_id
|
251
|
+
|
252
|
+
def _stack_id
|
253
|
+
_ref('AWS::StackId')
|
254
|
+
end
|
255
|
+
alias_method :stack_id!, :_stack_id
|
256
|
+
|
257
|
+
def _stack_name
|
258
|
+
_ref('AWS::StackName')
|
259
|
+
end
|
260
|
+
alias_method :stack_name!, :_stack_name
|
261
|
+
|
237
262
|
# Execute system command
|
238
263
|
#
|
239
264
|
# @param command [String]
|
@@ -243,6 +268,20 @@ class SparkleFormation
|
|
243
268
|
end
|
244
269
|
alias_method :system!, :_system
|
245
270
|
|
271
|
+
# @return [TrueClass, FalseClass] resource can be tagged
|
272
|
+
def taggable?
|
273
|
+
if(defined?(SfnAws))
|
274
|
+
if(self[:type])
|
275
|
+
resource = SfnAws.lookup(self[:type].gsub('::', '_').downcase)
|
276
|
+
resource && resource[:properties].include?('Tags')
|
277
|
+
else
|
278
|
+
if(self._parent)
|
279
|
+
self._parent.taggable?
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
246
285
|
# @return [TrueClass, FalseClass]
|
247
286
|
def rhel?
|
248
287
|
!!@platform[:rhel]
|
@@ -55,9 +55,9 @@ class SparkleFormation
|
|
55
55
|
def sparkle_path=(path=nil)
|
56
56
|
if(path)
|
57
57
|
custom_paths[:sparkle_path] = path
|
58
|
-
custom_paths[:components_directory]
|
59
|
-
custom_paths[:dynamics_directory]
|
60
|
-
custom_paths[:registry_directory]
|
58
|
+
custom_paths[:components_directory] = File.join(path, 'components')
|
59
|
+
custom_paths[:dynamics_directory] = File.join(path, 'dynamics')
|
60
|
+
custom_paths[:registry_directory] = File.join(path, 'registry')
|
61
61
|
end
|
62
62
|
custom_paths[:sparkle_path]
|
63
63
|
end
|
@@ -102,11 +102,17 @@ class SparkleFormation
|
|
102
102
|
# Compile file
|
103
103
|
#
|
104
104
|
# @param path [String] path to file
|
105
|
-
# @param args [Object] use :sparkle to return struct
|
105
|
+
# @param args [Object] use :sparkle to return struct. provide Hash
|
106
|
+
# to pass through when compiling ({:state => {}})
|
106
107
|
# @return [Hashish, SparkleStruct]
|
107
108
|
def compile(path, *args)
|
108
109
|
formation = self.instance_eval(IO.read(path), path, 1)
|
109
|
-
args.
|
110
|
+
if(args.delete(:sparkle))
|
111
|
+
formation
|
112
|
+
else
|
113
|
+
comp_arg = args.detect{|i| i.is_a?(Hash) }
|
114
|
+
(comp_arg ? formation.compile(comp_arg) : formation.compile)._dump
|
115
|
+
end
|
110
116
|
end
|
111
117
|
|
112
118
|
# Execute given block within struct context
|
@@ -252,7 +258,8 @@ class SparkleFormation
|
|
252
258
|
_name, _config = *args
|
253
259
|
_config ||= {}
|
254
260
|
return unless _name
|
255
|
-
|
261
|
+
resource_name = "#{_name}_#{_config.delete(:resource_name_suffix) || dynamic_name}".to_sym
|
262
|
+
new_resource = struct.resources.__send__(resource_name)
|
256
263
|
new_resource.type lookup_key
|
257
264
|
properties = new_resource.properties
|
258
265
|
SfnAws.resource(dynamic_name, :properties).each do |prop_name|
|
@@ -300,6 +307,8 @@ class SparkleFormation
|
|
300
307
|
attr_reader :components
|
301
308
|
# @return [Array] order of loading
|
302
309
|
attr_reader :load_order
|
310
|
+
# @return [Hash] parameters for stack generation
|
311
|
+
attr_reader :parameters
|
303
312
|
|
304
313
|
# Create new instance
|
305
314
|
#
|
@@ -309,6 +318,7 @@ class SparkleFormation
|
|
309
318
|
# @option options [String] :components_directory custom components path
|
310
319
|
# @option options [String] :dynamics_directory custom dynamics path
|
311
320
|
# @option options [String] :registry_directory custom registry path
|
321
|
+
# @option options [Hash] :parameters parameters for stack generation
|
312
322
|
# @option options [Truthy, Falsey] :disable_aws_builtins do not load builtins
|
313
323
|
# @yield base context
|
314
324
|
def initialize(name, options={}, &block)
|
@@ -331,6 +341,7 @@ class SparkleFormation
|
|
331
341
|
require 'sparkle_formation/aws'
|
332
342
|
SfnAws.load!
|
333
343
|
end
|
344
|
+
@parameters = set_generation_parameters!(options.fetch(:parameters, {}))
|
334
345
|
@components = SparkleStruct.hashish.new
|
335
346
|
@load_order = []
|
336
347
|
@overrides = []
|
@@ -340,6 +351,27 @@ class SparkleFormation
|
|
340
351
|
@compiled = nil
|
341
352
|
end
|
342
353
|
|
354
|
+
ALLOWED_GENERATION_PARAMETERS = ['type', 'default']
|
355
|
+
VALID_GENERATION_PARAMETER_TYPES = ['String', 'Number']
|
356
|
+
|
357
|
+
# Validation parameters used for template generation to ensure they
|
358
|
+
# are in the expected format
|
359
|
+
#
|
360
|
+
# @param params [Hash] parameter set
|
361
|
+
# @return [Hash] parameter set
|
362
|
+
# @raises [ArgumentError]
|
363
|
+
def set_generation_parameters!(params)
|
364
|
+
params.each do |name, value|
|
365
|
+
unless(value.is_a?(Hash))
|
366
|
+
raise TypeError.new("Expecting `Hash` type. Received `#{value.class}`")
|
367
|
+
end
|
368
|
+
if(key = value.keys.detect{|k| !ALLOWED_GENERATION_PARAMETERS.include?(k.to_s) })
|
369
|
+
raise ArgumentError.new("Invalid generation parameter key provided `#{key}`")
|
370
|
+
end
|
371
|
+
end
|
372
|
+
params
|
373
|
+
end
|
374
|
+
|
343
375
|
# Add block to load order
|
344
376
|
#
|
345
377
|
# @param block [Proc]
|
@@ -380,10 +412,15 @@ class SparkleFormation
|
|
380
412
|
|
381
413
|
# Compile the formation
|
382
414
|
#
|
415
|
+
# @param args [Hash]
|
416
|
+
# @option args [Hash] :state local state parameters
|
383
417
|
# @return [SparkleStruct]
|
384
|
-
def compile
|
418
|
+
def compile(args={})
|
385
419
|
unless(@compiled)
|
386
420
|
compiled = SparkleStruct.new
|
421
|
+
if(args[:state])
|
422
|
+
compiled.set_state!(args[:state])
|
423
|
+
end
|
387
424
|
@load_order.each do |key|
|
388
425
|
compiled._merge!(components[key])
|
389
426
|
end
|
@@ -429,7 +466,7 @@ class SparkleFormation
|
|
429
466
|
# @yieldparam template [Hash] nested stack template
|
430
467
|
# @yieldreturn [String] remote URL
|
431
468
|
# @return [Hash] dumped template hash
|
432
|
-
def apply_nesting
|
469
|
+
def apply_nesting(*args)
|
433
470
|
hash = compile.dump!
|
434
471
|
stacks = Hash[
|
435
472
|
hash['Resources'].find_all do |r_name, resource|
|
@@ -448,6 +485,18 @@ class SparkleFormation
|
|
448
485
|
resource['Properties']['TemplateURL'] = yield(resource_name, stack)
|
449
486
|
end
|
450
487
|
end
|
488
|
+
if(args.include?(:collect_outputs))
|
489
|
+
outputs_hash = Hash[
|
490
|
+
output_map do |name, value|
|
491
|
+
[name, {'Value' => {'Fn::GetAtt' => value}}]
|
492
|
+
end
|
493
|
+
]
|
494
|
+
if(hash['Outputs'])
|
495
|
+
hash['Outputs'].merge!(outputs_hash)
|
496
|
+
else
|
497
|
+
hash['Outputs'] = outputs_hash
|
498
|
+
end
|
499
|
+
end
|
451
500
|
hash
|
452
501
|
end
|
453
502
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparkle_formation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: attribute_struct
|