sparkle_formation 2.1.8 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/docs/README.md +1 -0
- data/docs/helper-methods.md +1 -0
- data/docs/provider-restrictions.md +174 -0
- data/docs/translation.md +3 -0
- data/lib/sparkle_formation.rb +3 -0
- data/lib/sparkle_formation/function_struct.rb +132 -4
- data/lib/sparkle_formation/provider.rb +1 -0
- data/lib/sparkle_formation/provider/aws.rb +4 -4
- data/lib/sparkle_formation/provider/azure.rb +4 -4
- data/lib/sparkle_formation/provider/google.rb +200 -0
- data/lib/sparkle_formation/provider/heat.rb +4 -4
- data/lib/sparkle_formation/resources.rb +106 -21
- data/lib/sparkle_formation/resources/aws.rb +252 -0
- data/lib/sparkle_formation/resources/aws_resources.json +117 -29
- data/lib/sparkle_formation/resources/google.rb +47 -0
- data/lib/sparkle_formation/resources/google_resources.json +667 -0
- data/lib/sparkle_formation/sparkle.rb +145 -120
- data/lib/sparkle_formation/sparkle_attribute.rb +60 -21
- data/lib/sparkle_formation/sparkle_attribute/aws.rb +27 -18
- data/lib/sparkle_formation/sparkle_attribute/azure.rb +25 -12
- data/lib/sparkle_formation/sparkle_attribute/google.rb +149 -0
- data/lib/sparkle_formation/sparkle_attribute/heat.rb +33 -14
- data/lib/sparkle_formation/sparkle_collection.rb +37 -15
- data/lib/sparkle_formation/sparkle_formation.rb +48 -22
- data/lib/sparkle_formation/sparkle_struct.rb +43 -0
- data/lib/sparkle_formation/version.rb +1 -1
- metadata +7 -2
@@ -95,7 +95,7 @@ class SparkleFormation
|
|
95
95
|
def compile(path, *args)
|
96
96
|
opts = args.detect{|i| i.is_a?(Hash) } || {}
|
97
97
|
unless(path.is_a?(String) && File.file?(path.to_s))
|
98
|
-
if(spath = (opts.delete(:sparkle_path) || SparkleFormation.sparkle_path))
|
98
|
+
if(spath = (opts.delete(:sparkle_path) || SparkleFormation.custom_paths[:sparkle_path]))
|
99
99
|
container = Sparkle.new(:root => spath)
|
100
100
|
path = container.get(:template, path)[:path]
|
101
101
|
end
|
@@ -200,7 +200,8 @@ class SparkleFormation
|
|
200
200
|
# @return [SparkleStruct]
|
201
201
|
def registry(registry_name, struct, *args)
|
202
202
|
__t_stringish(registry_name)
|
203
|
-
|
203
|
+
opts = args.detect{|item| item.is_a?(Hash)} || {}
|
204
|
+
reg = struct._self.sparkle.get(:registry, registry_name, opts[:provider])
|
204
205
|
struct.instance_exec(*args, ®[:block])
|
205
206
|
end
|
206
207
|
|
@@ -214,7 +215,9 @@ class SparkleFormation
|
|
214
215
|
__t_stringish(dynamic_name)
|
215
216
|
result = false
|
216
217
|
begin
|
217
|
-
|
218
|
+
opts = args.detect{|i| i.is_a?(Hash)} || {}
|
219
|
+
dyn = struct._self.sparkle.get(:dynamic, dynamic_name, opts[:provider])
|
220
|
+
opts = nil
|
218
221
|
raise dyn if dyn.is_a?(Exception)
|
219
222
|
dyn.monochrome.each do |dynamic_item|
|
220
223
|
if(result)
|
@@ -234,7 +237,7 @@ class SparkleFormation
|
|
234
237
|
result = builtin_insert(dynamic_name, struct, *args, &block)
|
235
238
|
unless(result)
|
236
239
|
message = "Failed to locate requested dynamic block for insertion: #{dynamic_name} " \
|
237
|
-
|
240
|
+
"(valid: #{struct._self.sparkle.dynamics.fetch(struct._self.sparkle.provider, {}).keys.sort.join(', ')})"
|
238
241
|
if(struct._self.provider_resources && struct._self.provider_resources.registry.keys.size > 1)
|
239
242
|
t_name = struct._self.provider_resources.registry.keys.first
|
240
243
|
valid_t_name = Bogo::Utility.snake(
|
@@ -268,7 +271,7 @@ class SparkleFormation
|
|
268
271
|
[template, *args].compact.each do |item|
|
269
272
|
__t_stringish(item)
|
270
273
|
end
|
271
|
-
to_nest = struct._self.sparkle.get(:template, template)
|
274
|
+
to_nest = struct._self.sparkle.get(:template, template, options[:provider])
|
272
275
|
resource_name = template.to_s.gsub('__', '_')
|
273
276
|
unless(args.empty?)
|
274
277
|
resource_name = [
|
@@ -276,23 +279,24 @@ class SparkleFormation
|
|
276
279
|
args.map{|a| Bogo::Utility.snake(a)}.join('_')
|
277
280
|
].flatten.compact.join('_').to_sym
|
278
281
|
end
|
282
|
+
resource_name = struct._process_key(resource_name.to_sym)
|
279
283
|
nested_template = compile(to_nest[:path], :sparkle)
|
280
284
|
nested_template.parent = struct._self
|
281
|
-
nested_template.name =
|
285
|
+
nested_template.name = resource_name
|
282
286
|
if(options[:parameters])
|
283
287
|
nested_template.compile_state = options[:parameters]
|
284
288
|
end
|
285
|
-
struct.resources.set!(resource_name) do
|
286
|
-
type struct._self.stack_resource_type
|
287
|
-
end
|
288
289
|
unless(struct._self.sparkle.empty?)
|
289
290
|
nested_template.sparkle.apply(struct._self.sparkle)
|
290
291
|
end
|
291
|
-
struct.
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
292
|
+
nested_resource = struct.dynamic!(
|
293
|
+
struct._self.stack_resource_type,
|
294
|
+
resource_name,
|
295
|
+
{:resource_name_suffix => nil},
|
296
|
+
&block
|
297
|
+
)
|
298
|
+
nested_resource.properties.stack nested_template
|
299
|
+
nested_resource
|
296
300
|
end
|
297
301
|
|
298
302
|
# Insert a builtin dynamic into a context
|
@@ -307,7 +311,11 @@ class SparkleFormation
|
|
307
311
|
_config ||= {}
|
308
312
|
__t_stringish(_name)
|
309
313
|
__t_hashish(_config)
|
310
|
-
resource_name =
|
314
|
+
resource_name = [
|
315
|
+
_name,
|
316
|
+
_config.fetch(:resource_name_suffix, dynamic_name)
|
317
|
+
].compact.join('_').to_sym
|
318
|
+
_config.delete(:resource_name_suffix)
|
311
319
|
new_resource = struct.resources.set!(resource_name)
|
312
320
|
new_resource.type lookup_key
|
313
321
|
properties = new_resource.properties
|
@@ -402,6 +410,8 @@ class SparkleFormation
|
|
402
410
|
)
|
403
411
|
if(s_path)
|
404
412
|
h[:root] = s_path
|
413
|
+
else
|
414
|
+
h[:root] = :none
|
405
415
|
end
|
406
416
|
}
|
407
417
|
)
|
@@ -531,6 +541,7 @@ class SparkleFormation
|
|
531
541
|
if(Provider.const_defined?(provider_klass))
|
532
542
|
extend Provider.const_get(provider_klass)
|
533
543
|
end
|
544
|
+
sparkle.provider = val
|
534
545
|
@provider
|
535
546
|
else
|
536
547
|
@provider = nil
|
@@ -629,7 +640,7 @@ class SparkleFormation
|
|
629
640
|
#
|
630
641
|
# @param args [String, Symbol] Symbol component names or String paths
|
631
642
|
# @return [self]
|
632
|
-
def load(*args)
|
643
|
+
def load(*args, &user_block)
|
633
644
|
args.each do |thing|
|
634
645
|
if(thing.is_a?(String))
|
635
646
|
# NOTE: This needs to be deprecated and removed
|
@@ -640,6 +651,9 @@ class SparkleFormation
|
|
640
651
|
composition.new_component(thing)
|
641
652
|
end
|
642
653
|
end
|
654
|
+
if(block_given?)
|
655
|
+
block(user_block)
|
656
|
+
end
|
643
657
|
self
|
644
658
|
end
|
645
659
|
|
@@ -791,7 +805,7 @@ class SparkleFormation
|
|
791
805
|
# Apply nesting logic to stack
|
792
806
|
#
|
793
807
|
# @param nest_type [Symbol] values: :shallow, :deep (default: :deep)
|
794
|
-
# @return [
|
808
|
+
# @return [SparkleFormation::SparkleStruct] compiled structure
|
795
809
|
# @note see specific version for expected block parameters
|
796
810
|
def apply_nesting(*args, &block)
|
797
811
|
if(args.include?(:shallow))
|
@@ -810,9 +824,9 @@ class SparkleFormation
|
|
810
824
|
# @yieldparam resource [AttributeStruct] the stack resource
|
811
825
|
# @yieldparam s_name [String] stack resource name
|
812
826
|
# @yieldreturn [Hash] key/values to be merged into resource properties
|
813
|
-
# @return [
|
827
|
+
# @return [SparkleFormation::SparkleStruct] compiled structure
|
814
828
|
def apply_deep_nesting(*args, &block)
|
815
|
-
compile
|
829
|
+
compile
|
816
830
|
end
|
817
831
|
|
818
832
|
# Check if parameter name matches an output name
|
@@ -855,7 +869,10 @@ class SparkleFormation
|
|
855
869
|
unless(stack.nested_stacks.empty?)
|
856
870
|
stack_template_extractor(stack.nested_stacks(:with_resource, :with_name), &block)
|
857
871
|
end
|
858
|
-
resource.properties.
|
872
|
+
resource.properties._delete(:stack)
|
873
|
+
s_parent = resource.properties.stack
|
874
|
+
stack.compile._parent(s_parent)
|
875
|
+
resource.properties.set!(:stack, stack.compile)
|
859
876
|
block.call(s_name, stack, resource)
|
860
877
|
end
|
861
878
|
end
|
@@ -868,9 +885,9 @@ class SparkleFormation
|
|
868
885
|
# @yieldparam resource_name [String] name of stack resource
|
869
886
|
# @yieldparam stack [SparkleFormation] nested stack
|
870
887
|
# @yieldreturn [String] Remote URL storage for template
|
871
|
-
# @return [
|
888
|
+
# @return [SparkleFormation::SparkleStruct] compiled structure
|
872
889
|
def apply_shallow_nesting(*args, &block)
|
873
|
-
compile
|
890
|
+
compile
|
874
891
|
end
|
875
892
|
|
876
893
|
# @return [Smash<output_name:SparkleFormation>]
|
@@ -917,6 +934,15 @@ class SparkleFormation
|
|
917
934
|
MultiJson.load(to_json)
|
918
935
|
end
|
919
936
|
|
937
|
+
# @return [Hash] dumped hash
|
938
|
+
def sparkle_dump
|
939
|
+
MultiJson.load(
|
940
|
+
MultiJson.dump(
|
941
|
+
compile.sparkle_dump!
|
942
|
+
)
|
943
|
+
)
|
944
|
+
end
|
945
|
+
|
920
946
|
# @return [String] dumped hash JSON
|
921
947
|
def to_json(*args)
|
922
948
|
# NOTE: Ported in from batali
|
@@ -130,5 +130,48 @@ class SparkleFormation
|
|
130
130
|
end
|
131
131
|
alias_method :state!, :_state
|
132
132
|
|
133
|
+
# TODO: Need to refactor attribute_struct dumping to allow hooking
|
134
|
+
# custom behavior instead of heavy copy/paste to modify a method call
|
135
|
+
|
136
|
+
# Process and unpack items for dumping within deeply nested
|
137
|
+
# enumerable types
|
138
|
+
#
|
139
|
+
# @param item [Object]
|
140
|
+
# @return [Object]
|
141
|
+
def _sparkle_dump_unpacker(item)
|
142
|
+
if(item.is_a?(::Enumerable))
|
143
|
+
if(item.respond_to?(:keys))
|
144
|
+
item.class[
|
145
|
+
*item.map do |entry|
|
146
|
+
_sparkle_dump_unpacker(entry)
|
147
|
+
end.flatten(1)
|
148
|
+
]
|
149
|
+
else
|
150
|
+
item.class[
|
151
|
+
*item.map do |entry|
|
152
|
+
_sparkle_dump_unpacker(entry)
|
153
|
+
end
|
154
|
+
]
|
155
|
+
end
|
156
|
+
elsif(item.is_a?(::AttributeStruct))
|
157
|
+
item.nil? ? UNSET_VALUE : item._sparkle_dump
|
158
|
+
elsif(item.is_a?(::SparkleFormation))
|
159
|
+
item.sparkle_dump
|
160
|
+
else
|
161
|
+
item
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# @return [AttributeStruct::AttributeHash, Mash] dump struct to hashish
|
166
|
+
def _sparkle_dump
|
167
|
+
processed = @table.keys.map do |key|
|
168
|
+
value = @table[key]
|
169
|
+
val = _sparkle_dump_unpacker(value)
|
170
|
+
[_sparkle_dump_unpacker(key), val] unless val == UNSET_VALUE
|
171
|
+
end.compact
|
172
|
+
__hashish[*processed.flatten(1)]
|
173
|
+
end
|
174
|
+
alias_method :sparkle_dump!, :_sparkle_dump
|
175
|
+
|
133
176
|
end
|
134
177
|
end
|
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:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: attribute_struct
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- docs/inheritance-merging.md
|
162
162
|
- docs/nested-stacks.md
|
163
163
|
- docs/overview.md
|
164
|
+
- docs/provider-restrictions.md
|
164
165
|
- docs/sparkle-packs.md
|
165
166
|
- docs/sparkleformation-dsl.md
|
166
167
|
- docs/stack-policies.md
|
@@ -180,12 +181,15 @@ files:
|
|
180
181
|
- lib/sparkle_formation/provider.rb
|
181
182
|
- lib/sparkle_formation/provider/aws.rb
|
182
183
|
- lib/sparkle_formation/provider/azure.rb
|
184
|
+
- lib/sparkle_formation/provider/google.rb
|
183
185
|
- lib/sparkle_formation/provider/heat.rb
|
184
186
|
- lib/sparkle_formation/resources.rb
|
185
187
|
- lib/sparkle_formation/resources/aws.rb
|
186
188
|
- lib/sparkle_formation/resources/aws_resources.json
|
187
189
|
- lib/sparkle_formation/resources/azure.rb
|
188
190
|
- lib/sparkle_formation/resources/azure_resources.json
|
191
|
+
- lib/sparkle_formation/resources/google.rb
|
192
|
+
- lib/sparkle_formation/resources/google_resources.json
|
189
193
|
- lib/sparkle_formation/resources/heat.rb
|
190
194
|
- lib/sparkle_formation/resources/heat_resources.json
|
191
195
|
- lib/sparkle_formation/resources/rackspace.rb
|
@@ -194,6 +198,7 @@ files:
|
|
194
198
|
- lib/sparkle_formation/sparkle_attribute.rb
|
195
199
|
- lib/sparkle_formation/sparkle_attribute/aws.rb
|
196
200
|
- lib/sparkle_formation/sparkle_attribute/azure.rb
|
201
|
+
- lib/sparkle_formation/sparkle_attribute/google.rb
|
197
202
|
- lib/sparkle_formation/sparkle_attribute/heat.rb
|
198
203
|
- lib/sparkle_formation/sparkle_attribute/rackspace.rb
|
199
204
|
- lib/sparkle_formation/sparkle_collection.rb
|