sparkle_formation 3.0.26 → 3.0.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +6 -0
  3. data/lib/sparkle_formation/composition.rb +17 -17
  4. data/lib/sparkle_formation/error.rb +2 -5
  5. data/lib/sparkle_formation/function_struct.rb +27 -31
  6. data/lib/sparkle_formation/provider/aws.rb +32 -31
  7. data/lib/sparkle_formation/provider/azure.rb +18 -19
  8. data/lib/sparkle_formation/provider/google.rb +20 -22
  9. data/lib/sparkle_formation/provider/heat.rb +17 -17
  10. data/lib/sparkle_formation/provider/terraform.rb +14 -15
  11. data/lib/sparkle_formation/provider.rb +0 -2
  12. data/lib/sparkle_formation/resources/aws.rb +129 -149
  13. data/lib/sparkle_formation/resources/aws_resources.json +9208 -5542
  14. data/lib/sparkle_formation/resources/azure.rb +2 -5
  15. data/lib/sparkle_formation/resources/azure_resources.json +12367 -2901
  16. data/lib/sparkle_formation/resources/google.rb +1 -4
  17. data/lib/sparkle_formation/resources/heat.rb +0 -4
  18. data/lib/sparkle_formation/resources/heat_resources.json +2616 -2062
  19. data/lib/sparkle_formation/resources/rackspace.rb +0 -4
  20. data/lib/sparkle_formation/resources/terraform.rb +2 -6
  21. data/lib/sparkle_formation/resources.rb +20 -24
  22. data/lib/sparkle_formation/sparkle.rb +56 -66
  23. data/lib/sparkle_formation/sparkle_attribute/aws.rb +61 -34
  24. data/lib/sparkle_formation/sparkle_attribute/azure.rb +12 -8
  25. data/lib/sparkle_formation/sparkle_attribute/google.rb +18 -15
  26. data/lib/sparkle_formation/sparkle_attribute/heat.rb +22 -7
  27. data/lib/sparkle_formation/sparkle_attribute/rackspace.rb +0 -2
  28. data/lib/sparkle_formation/sparkle_attribute/terraform.rb +11 -5
  29. data/lib/sparkle_formation/sparkle_attribute.rb +13 -7
  30. data/lib/sparkle_formation/sparkle_collection/rainbow.rb +5 -7
  31. data/lib/sparkle_formation/sparkle_collection.rb +13 -15
  32. data/lib/sparkle_formation/sparkle_formation.rb +116 -112
  33. data/lib/sparkle_formation/sparkle_struct.rb +30 -24
  34. data/lib/sparkle_formation/translation/heat.rb +57 -58
  35. data/lib/sparkle_formation/translation/rackspace.rb +48 -49
  36. data/lib/sparkle_formation/translation.rb +34 -37
  37. data/lib/sparkle_formation/utils.rb +6 -13
  38. data/lib/sparkle_formation/version.rb +1 -1
  39. data/sparkle_formation.gemspec +1 -1
  40. metadata +9 -9
@@ -7,9 +7,7 @@ class SparkleFormation
7
7
 
8
8
  # Rackspace specific resources collection
9
9
  class Rackspace < Resources
10
-
11
10
  class << self
12
-
13
11
  include Bogo::Memoization
14
12
 
15
13
  # Load the builtin AWS resources
@@ -31,9 +29,7 @@ class SparkleFormation
31
29
  def included(_klass)
32
30
  load!
33
31
  end
34
-
35
32
  end
36
-
37
33
  end
38
34
  end
39
35
  end
@@ -12,7 +12,6 @@ class SparkleFormation
12
12
  RESOURCE_TYPE_NAMESPACE_SPLITTER = ['_']
13
13
 
14
14
  class << self
15
-
16
15
  include Bogo::Memoization
17
16
 
18
17
  # Load the builtin Terraform resources
@@ -28,9 +27,8 @@ class SparkleFormation
28
27
  )
29
28
  # NOTE: Internal resource type used for nesting
30
29
  register('module',
31
- 'properties' => [],
32
- 'full_properties' => {}
33
- )
30
+ 'properties' => [],
31
+ 'full_properties' => {})
34
32
  true
35
33
  end
36
34
  end
@@ -39,9 +37,7 @@ class SparkleFormation
39
37
  def included(_klass)
40
38
  load!
41
39
  end
42
-
43
40
  end
44
-
45
41
  end
46
42
  end
47
43
  end
@@ -3,7 +3,6 @@ require 'sparkle_formation'
3
3
  class SparkleFormation
4
4
  # Resources helper
5
5
  class Resources
6
-
7
6
  autoload :Aws, 'sparkle_formation/resources/aws'
8
7
  autoload :Azure, 'sparkle_formation/resources/azure'
9
8
  autoload :Google, 'sparkle_formation/resources/google'
@@ -56,14 +55,14 @@ class SparkleFormation
56
55
  #
57
56
  # @param final_resource [Hash] desired resource structure containing this property
58
57
  # @return ['replacement', 'interrupt', 'unknown', 'none']
59
- def update_causes(final_resource=nil, original_resource=nil)
60
- if(conditionals && final_resource)
58
+ def update_causes(final_resource = nil, original_resource = nil)
59
+ if conditionals && final_resource
61
60
  final_resource = final_resource.to_smash
62
61
  original_resource = original_resource.to_smash
63
62
  result = conditionals.detect do |p_cond|
64
63
  p_cond.conditional == true || p_cond.conditional.call(final_resource, original_resource)
65
64
  end
66
- if(result)
65
+ if result
67
66
  result.update_causes
68
67
  else
69
68
  'unknown'
@@ -75,7 +74,6 @@ class SparkleFormation
75
74
  end
76
75
 
77
76
  class << self
78
-
79
77
  include SparkleFormation::Utils::AnimalStrings
80
78
  # @!parse include SparkleFormation::Utils::AnimalStrings
81
79
 
@@ -90,10 +88,10 @@ class SparkleFormation
90
88
  # @param hash [Hash] metadata information
91
89
  # @return [TrueClass]
92
90
  def register(type, hash)
93
- unless(hash.is_a?(Hash))
91
+ unless hash.is_a?(Hash)
94
92
  raise TypeError.new("Expecting `Hash` type but received `#{hash.class}`")
95
93
  end
96
- unless(class_variable_defined?(:@@registry))
94
+ unless class_variable_defined?(:@@registry)
97
95
  @@registry = AttributeStruct.hashish.new
98
96
  end
99
97
  @@registry[base_key] ||= AttributeStruct.hashish.new
@@ -106,9 +104,9 @@ class SparkleFormation
106
104
  # @param identifier [String, Symbol] resource identifier
107
105
  # @param key [String, Symbol] specific data
108
106
  # @return [Hashish, NilClass]
109
- def resource(identifier, key=nil)
107
+ def resource(identifier, key = nil)
110
108
  res = lookup(identifier)
111
- if(key && res)
109
+ if key && res
112
110
  res[key.to_sym]
113
111
  else
114
112
  res
@@ -146,7 +144,7 @@ class SparkleFormation
146
144
  # @param key [String, Symbol]
147
145
  # @return [String, NilClass]
148
146
  def registry_key(key)
149
- if(registry[key])
147
+ if registry[key]
150
148
  result = key
151
149
  else
152
150
  o_key = key
@@ -155,21 +153,21 @@ class SparkleFormation
155
153
  result = @@registry[base_key].keys.detect do |ref|
156
154
  ref = ref.downcase
157
155
  snake_parts = ref.split(resource_type_splitter)
158
- until(snake_parts.empty?)
156
+ until snake_parts.empty?
159
157
  break if snake_parts.join('') == key
160
158
  snake_parts.shift
161
159
  end
162
160
  !snake_parts.empty?
163
161
  end
164
- if(result)
162
+ if result
165
163
  collisions = @@registry[base_key].keys.find_all do |ref|
166
164
  split_ref = ref.downcase.split(resource_type_splitter)
167
165
  ref = Array(split_ref.slice(split_ref.size - snake_parts.size, split_ref.size)).join('')
168
166
  key == ref
169
167
  end
170
- if(collisions.size > 1)
168
+ if collisions.size > 1
171
169
  raise ArgumentError.new 'Ambiguous dynamic name returned multiple matches! ' \
172
- "`#{o_key.inspect}` -> #{collisions.sort.join(', ')}"
170
+ "`#{o_key.inspect}` -> #{collisions.sort.join(', ')}"
173
171
  end
174
172
  end
175
173
  end
@@ -180,7 +178,7 @@ class SparkleFormation
180
178
  # rubocop:disable Style/RedundantSelf
181
179
  def resource_type_splitter
182
180
  Regexp.new(
183
- [self.const_get(:RESOURCE_TYPE_NAMESPACE_SPLITTER)].flatten.compact.map{|value|
181
+ [self.const_get(:RESOURCE_TYPE_NAMESPACE_SPLITTER)].flatten.compact.map { |value|
184
182
  Regexp.escape(value)
185
183
  }.join('|')
186
184
  )
@@ -196,7 +194,7 @@ class SparkleFormation
196
194
 
197
195
  # @return [Hashish] currently loaded AWS registry
198
196
  def registry
199
- unless(class_variable_defined?(:@@registry))
197
+ unless class_variable_defined?(:@@registry)
200
198
  @@registry = AttributeStruct.hashish.new
201
199
  end
202
200
  @@registry[base_key]
@@ -218,22 +216,20 @@ class SparkleFormation
218
216
  # @return [Resource]
219
217
  def resource_lookup(type)
220
218
  result = registry[type]
221
- if(result)
219
+ if result
222
220
  properties = result.fetch('full_properties', {}).map do |p_name, p_info|
223
221
  Property.new(p_name,
224
- p_info[:description],
225
- p_info[:type],
226
- p_info[:required],
227
- p_info[:update_causes],
228
- self.const_get(:PROPERTY_UPDATE_CONDITIONALS).get(type, p_name)
229
- )
222
+ p_info[:description],
223
+ p_info[:type],
224
+ p_info[:required],
225
+ p_info[:update_causes],
226
+ self.const_get(:PROPERTY_UPDATE_CONDITIONALS).get(type, p_name))
230
227
  end
231
228
  Resource.new(type, properties, result)
232
229
  else
233
230
  raise KeyError.new "Failed to locate requested resource type: `#{type}`"
234
231
  end
235
232
  end
236
-
237
233
  end
238
234
  end
239
235
  end
@@ -15,24 +15,22 @@ class SparkleFormation
15
15
 
16
16
  # @!visibility private
17
17
  class SparkleFormation
18
-
19
18
  attr_accessor :sparkle_path
20
19
 
21
20
  class << self
22
-
23
21
  def insert(*args, &block)
24
22
  ::SparkleFormation.insert(*args, &block)
25
23
  end
26
24
 
27
- def part_data(data=nil)
28
- if(data)
25
+ def part_data(data = nil)
26
+ if data
29
27
  @data = data
30
28
  else
31
29
  @data
32
30
  end
33
31
  end
34
32
 
35
- def dynamic(name, args={}, &block)
33
+ def dynamic(name, args = {}, &block)
36
34
  part_data[:dynamic].push(
37
35
  ::Smash.new(
38
36
  :name => name,
@@ -40,7 +38,7 @@ class SparkleFormation
40
38
  :args => ::Smash[
41
39
  args.map(&:to_a)
42
40
  ],
43
- :type => :dynamic
41
+ :type => :dynamic,
44
42
  )
45
43
  ).last
46
44
  end
@@ -49,12 +47,12 @@ class SparkleFormation
49
47
  part_data[:component].push(
50
48
  ::Smash.new(
51
49
  :block => block,
52
- :type => :component
50
+ :type => :component,
53
51
  )
54
52
  ).last
55
53
  end
56
54
 
57
- def component(name, args={}, &block)
55
+ def component(name, args = {}, &block)
58
56
  part_data[:component].push(
59
57
  ::Smash.new(
60
58
  :name => name,
@@ -62,7 +60,7 @@ class SparkleFormation
62
60
  :args => ::Smash[
63
61
  args.map(&:to_a)
64
62
  ],
65
- :type => :component
63
+ :type => :component,
66
64
  )
67
65
  ).last
68
66
  end
@@ -70,15 +68,14 @@ class SparkleFormation
70
68
  def dynamic_info(*args)
71
69
  ::Smash.new(:metadata => {}, :args => {})
72
70
  end
73
-
74
71
  end
75
72
 
76
73
  def initialize(*args)
77
- opts = args.detect{|a| a.is_a?(Hash)} || {}
74
+ opts = args.detect { |a| a.is_a?(Hash) } || {}
78
75
  SparkleFormation.part_data[:template].push(
79
76
  ::Smash.new(
80
77
  :name => args.first,
81
- :args => opts
78
+ :args => opts,
82
79
  )
83
80
  )
84
81
  raise ::TypeError
@@ -86,8 +83,7 @@ class SparkleFormation
86
83
 
87
84
  # @!visibility private
88
85
  class Registry
89
-
90
- def self.register(name, args={}, &block)
86
+ def self.register(name, args = {}, &block)
91
87
  SparkleFormation.part_data[:registry].push(
92
88
  ::Smash.new(
93
89
  :name => name,
@@ -95,11 +91,10 @@ class SparkleFormation
95
91
  :args => ::Smash[
96
92
  args.map(&:to_a)
97
93
  ],
98
- :type => :registry
94
+ :type => :registry,
99
95
  )
100
96
  ).last
101
97
  end
102
-
103
98
  end
104
99
  end
105
100
 
@@ -109,16 +104,17 @@ class SparkleFormation
109
104
  # NOTE: Enable access to top level constants but do not
110
105
  # include deprecated constants to prevent warning outputs
111
106
  deprecated_constants = [
107
+ :Data,
112
108
  :Config,
113
109
  :TimeoutError,
114
110
  :Fixnum,
115
111
  :Bignum,
116
112
  :NIL,
117
113
  :TRUE,
118
- :FALSE
114
+ :FALSE,
119
115
  ]
120
116
  ::Object.constants.each do |const|
121
- unless(self.const_defined?(const)) # rubocop:disable Style/RedundantSelf
117
+ unless (self.const_defined?(const)) # rubocop:disable Style/RedundantSelf
122
118
  next if deprecated_constants.include?(const)
123
119
  self.const_set(const, ::Object.const_get(const)) # rubocop:disable Style/RedundantSelf
124
120
  end
@@ -128,11 +124,9 @@ class SparkleFormation
128
124
  def part_data(arg)
129
125
  SparkleFormation.part_data(arg)
130
126
  end
131
-
132
127
  end
133
128
 
134
129
  class << self
135
-
136
130
  @@_pack_registry = Smash.new
137
131
 
138
132
  # Register a SparklePack for short name access
@@ -140,8 +134,8 @@ class SparkleFormation
140
134
  # @param name [String, Symbol] name of pack
141
135
  # @param path [String] path to pack
142
136
  # @return [Array<String:name, String:path>]
143
- def register!(name=nil, path=nil)
144
- unless(path)
137
+ def register!(name = nil, path = nil)
138
+ unless path
145
139
  idx = caller.index do |item|
146
140
  item.end_with?("`register!'")
147
141
  end
@@ -150,23 +144,23 @@ class SparkleFormation
150
144
  # to not be improperly truncated
151
145
  file = caller[idx].split(':').reverse.drop(2).reverse.join(':')
152
146
  path = File.join(File.dirname(file), 'sparkleformation')
153
- unless(File.directory?(path))
147
+ unless File.directory?(path)
154
148
  path = nil
155
149
  end
156
- unless(name)
150
+ unless name
157
151
  name = File.basename(file)
158
152
  name.sub!(File.extname(name), '')
159
153
  end
160
154
  end
161
- unless(name)
162
- if(path)
155
+ unless name
156
+ if path
163
157
  name = path.split(File::PATH_SEPARATOR)[-3].to_s
164
158
  end
165
159
  end
166
- unless(path)
160
+ unless path
167
161
  raise ArgumentError.new('No SparklePack path provided and failed to auto-detect!')
168
162
  end
169
- unless(name)
163
+ unless name
170
164
  raise ArgumentError.new('No SparklePack name provided and failed to auto-detect!')
171
165
  end
172
166
  @@_pack_registry[name] = path
@@ -179,13 +173,12 @@ class SparkleFormation
179
173
  # @param name [String, Symbol] name of pack
180
174
  # @return [String] path
181
175
  def path(name)
182
- if(@@_pack_registry[name])
176
+ if @@_pack_registry[name]
183
177
  @@_pack_registry[name]
184
178
  else
185
179
  raise KeyError.new "No pack registered with requested name: #{name}!"
186
180
  end
187
181
  end
188
-
189
182
  end
190
183
 
191
184
  # Wrapper for evaluating sfn files to store within sparkle
@@ -202,14 +195,14 @@ class SparkleFormation
202
195
  'sfn',
203
196
  'cloudformation',
204
197
  'cfn',
205
- '.'
198
+ '.',
206
199
  ]
207
200
 
208
201
  # Reserved directories
209
202
  DIRS = [
210
203
  'components',
211
204
  'registry',
212
- 'dynamics'
205
+ 'dynamics',
213
206
  ]
214
207
 
215
208
  # Valid types
@@ -217,7 +210,7 @@ class SparkleFormation
217
210
  'component' => 'components',
218
211
  'registry' => 'registries',
219
212
  'dynamic' => 'dynamics',
220
- 'template' => 'templates'
213
+ 'template' => 'templates',
221
214
  )
222
215
 
223
216
  # @return [String] path to sparkle directories
@@ -234,20 +227,20 @@ class SparkleFormation
234
227
  # @option args [String, Symbol] :name registered pack name
235
228
  # @option args [String, Symbol] :provider name of default provider
236
229
  # @return [self]
237
- def initialize(args={})
238
- if(args[:name])
230
+ def initialize(args = {})
231
+ if args[:name]
239
232
  @root = self.class.path(args[:name])
240
233
  else
241
234
  @root = args.fetch(:root, locate_root)
242
235
  end
243
- if(@root != :none && !File.directory?(@root))
236
+ if @root != :none && !File.directory?(@root)
244
237
  raise Errno::ENOENT.new("No such directory - #{@root}")
245
238
  end
246
239
  @raw_data = Smash.new(
247
240
  :dynamic => [],
248
241
  :component => [],
249
242
  :registry => [],
250
- :template => []
243
+ :template => [],
251
244
  )
252
245
  @provider = Bogo::Utility.snake(args.fetch(:provider, 'aws').to_s).to_sym
253
246
  @wrapper = eval_wrapper.new
@@ -290,27 +283,25 @@ class SparkleFormation
290
283
  # @param target_provider [String, Symbol] restrict to provider
291
284
  # @return [Smash] requested item
292
285
  # @raises [NameError, Error::NotFound]
293
- def get(type, name, target_provider=nil)
294
- unless(TYPES.keys.include?(type.to_s))
286
+ def get(type, name, target_provider = nil)
287
+ unless TYPES.keys.include?(type.to_s)
295
288
  raise NameError.new "Invalid type requested (#{type})! Valid types: #{TYPES.keys.join(', ')}"
296
289
  end
297
- unless(target_provider)
290
+ unless target_provider
298
291
  target_provider = provider
299
292
  end
300
293
  result = send(TYPES[type]).get(target_provider, name)
301
- if(result.nil? && TYPES[type] == 'templates')
302
- result = (
303
- send(TYPES[type]).fetch(target_provider, Smash.new).detect{|_, v|
304
- name = name.to_s
305
- short_name = v[:path].sub(%r{#{Regexp.escape(root)}/?}, '')
306
- v[:path] == name ||
307
- short_name == name ||
308
- short_name.sub('.rb', '').gsub(File::SEPARATOR, '__').tr('-', '_') == name ||
309
- v[:path].end_with?(name)
310
- } || []
311
- ).last
294
+ if result.nil? && TYPES[type] == 'templates'
295
+ result = (send(TYPES[type]).fetch(target_provider, Smash.new).detect { |_, v|
296
+ name = name.to_s
297
+ short_name = v[:path].sub(%r{#{Regexp.escape(root)}/?}, '')
298
+ v[:path] == name ||
299
+ short_name == name ||
300
+ short_name.sub('.rb', '').gsub(File::SEPARATOR, '__').tr('-', '_') == name ||
301
+ v[:path].end_with?(name)
302
+ } || []).last
312
303
  end
313
- unless(result)
304
+ unless result
314
305
  klass = Error::NotFound.const_get(type.capitalize)
315
306
  raise klass.new("No #{type} registered with requested name (#{name})!", :name => name)
316
307
  end
@@ -333,7 +324,7 @@ class SparkleFormation
333
324
  def locate_root
334
325
  VALID_ROOT_DIRS.map do |part|
335
326
  path = File.expand_path(File.join(Dir.pwd, part))
336
- if(File.exist?(path))
327
+ if File.exist?(path)
337
328
  path
338
329
  end
339
330
  end.compact.first
@@ -344,33 +335,32 @@ class SparkleFormation
344
335
  memoize(:load_parts) do
345
336
  Dir.glob(File.join(root, '**', '**', '*.{json,rb}')).each do |file|
346
337
  slim_path = file.sub("#{root}/", '')
347
- if(file.end_with?('.rb'))
338
+ if file.end_with?('.rb')
348
339
  begin
349
340
  wrapper.instance_eval(IO.read(file), file, 1)
350
341
  rescue TypeError
351
342
  end
352
343
  end
353
- if(file.end_with?('.json') || raw_data[:template].first)
344
+ if file.end_with?('.json') || raw_data[:template].first
354
345
  data = raw_data[:template].pop || Smash.new
355
- unless(data[:name])
346
+ unless data[:name]
356
347
  data[:name] = slim_path.tr('/', '__').sub(/\.(rb|json)$/, '')
357
348
  end
358
349
  t_provider = data.fetch(:args, :provider, :aws)
359
- if(templates.get(t_provider, data[:name]))
350
+ if templates.get(t_provider, data[:name])
360
351
  raise KeyError.new "Template name is already in use within pack! (`#{data[:name]}` -> `#{t_provider}`)"
361
352
  end
362
353
  templates.set(t_provider, data[:name],
363
- data.merge(
364
- :type => :template,
365
- :path => file,
366
- :serialized => !file.end_with?('.rb')
367
- )
368
- )
354
+ data.merge(
355
+ :type => :template,
356
+ :path => file,
357
+ :serialized => !file.end_with?('.rb'),
358
+ ))
369
359
  end
370
360
  end
371
361
  raw_data.each do |key, items|
372
362
  items.each do |item|
373
- if(item[:name])
363
+ if item[:name]
374
364
  collection = send(TYPES[key])
375
365
  name = item.delete(:name)
376
366
  else
@@ -379,7 +369,7 @@ class SparkleFormation
379
369
  collection = send(type)
380
370
  end
381
371
  i_provider = item.fetch(:args, :provider, :aws)
382
- if(collection.get(i_provider, name))
372
+ if collection.get(i_provider, name)
383
373
  raise KeyError.new "#{key.capitalize} name is already in use within pack! (`#{name}` -> #{i_provider})"
384
374
  end
385
375
  collection.set(i_provider, name, item)
@@ -387,8 +377,8 @@ class SparkleFormation
387
377
  end
388
378
  end
389
379
  end
390
-
391
380
  end
381
+
392
382
  # Alias for interfacing naming
393
383
  SparklePack = Sparkle
394
384
  end