cfhighlander 0.2.1.alpha.27 → 0.2.1.alpha.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc0e66ec10442d67a675f046539b949e2b2a1a2d77b777a469015c889173020d
4
- data.tar.gz: de465ad3600e11b5147f8c888d6e59d908acc10a2996cfcbb300e73f6821da96
3
+ metadata.gz: 243c9e2f57eb637952b598302942a48d166a3189e0a4a7698d918224cd3193ce
4
+ data.tar.gz: d20c212d3b8a47a6f64e530ec412644a49f5c6ea3d0c93e506b7aa87cc6347f8
5
5
  SHA512:
6
- metadata.gz: 3a935570dbe5ccc7e506a5a1467aef5b2c1233a3a8b7e362f1b7a29283d54574f8cba53d1a91ac54a72c46c9416d0945594b59ebdfc86933814f84d9d78997e0
7
- data.tar.gz: 882d53c4237694d3d3cf89f971fcbb1aa57dd0202d80dbe3ab659b8ecf054d6fda8d246460efa8968a0cbc4bf08ef0a6e3d0d48bb259166937d2305d857ad3f7
6
+ metadata.gz: afbb5e1be2f09e04e577f335a6f3e1155a7ef1688064966253b594199cbe48491e7fb5d49c8efcc9780b736471f51d290b2c510b1718efc3f40f479b94e16648
7
+ data.tar.gz: 23d771ecf5399a83d25bfd77f3ac3d1c6d5d0989f1f455d54c23a0f04b11015726446f38b1e0645339465735efdfe09d2ccb5cefae9a7f63817598aa56af33d7
data/bin/cfhighlander.rb CHANGED
@@ -22,11 +22,11 @@ class HighlanderCli < Thor
22
22
 
23
23
  desc 'configcompile component[@version]', 'Compile Highlander components configuration'
24
24
 
25
- def configcompile(component_name)
25
+ def configcompile(template_name)
26
26
 
27
27
  # find and load component
28
28
  component_loader = Highlander::Factory::ComponentFactory.new
29
- component = component_loader.findComponent(component_name)
29
+ component = component_loader.loadComponentFromTemplate(template_name)
30
30
  component.load
31
31
 
32
32
  # compile cfndsl template
@@ -117,14 +117,14 @@ class HighlanderCli < Thor
117
117
  method_option :version, :type => :string, :required => false, :default => nil, :aliases => '-v',
118
118
  :desc => 'Distribution component version, defaults to latest'
119
119
 
120
- def publish(component_name)
120
+ def publish(template_name)
121
121
  component_version = options[:version]
122
122
  distribution_bucket = options[:dstbucket]
123
123
  distribution_prefix = options[:dstprefix]
124
124
 
125
125
  # find and load component
126
126
  component_loader = Highlander::Factory::ComponentFactory.new
127
- component = component_loader.findComponent(component_name)
127
+ component = component_loader.loadComponentFromTemplate(template_name)
128
128
  component.version = component_version
129
129
  component.distribution_bucket = distribution_bucket unless distribution_bucket.nil?
130
130
  component.distribution_prefix = distribution_prefix unless distribution_prefix.nil?
@@ -137,7 +137,7 @@ class HighlanderCli < Thor
137
137
  end
138
138
 
139
139
  # build component from passed cli options
140
- def build_component(options, component_name)
140
+ def build_component(options, template_name)
141
141
 
142
142
  component_version = options[:version]
143
143
  distribution_bucket = options[:dstbucket]
@@ -145,7 +145,7 @@ def build_component(options, component_name)
145
145
 
146
146
  # find and load component
147
147
  component_loader = Highlander::Factory::ComponentFactory.new
148
- component = component_loader.findComponent(component_name)
148
+ component = component_loader.loadComponentFromTemplate(template_name)
149
149
  component.version = component_version unless component_version.nil?
150
150
  component.distribution_bucket = distribution_bucket unless distribution_bucket.nil?
151
151
  component.distribution_prefix = distribution_prefix unless distribution_prefix.nil?
@@ -66,9 +66,10 @@ module Highlander
66
66
 
67
67
  # load component
68
68
  factory = Highlander::Factory::ComponentFactory.new(@component_sources)
69
- @component_loaded = factory.findComponent(
69
+ @component_loaded = factory.loadComponentFromTemplate(
70
70
  @template,
71
- @template_version
71
+ @template_version,
72
+ @name
72
73
  )
73
74
  @component_loaded.config.extend @config
74
75
 
@@ -176,7 +177,7 @@ module Highlander
176
177
  key_name = nil
177
178
 
178
179
  # priority 0: stack-level parameter of map name
179
- stack_param_mapname = component.parameters.param_list.find { |p| p.name == mappings_name }
180
+ stack_param_mapname = component.parameters.param_list.find {|p| p.name == mappings_name}
180
181
  unless stack_param_mapname.nil?
181
182
  key_name = "Ref('#{mappings_name}')"
182
183
  end
@@ -195,7 +196,7 @@ module Highlander
195
196
  # could still be nil after this line
196
197
  end
197
198
 
198
- value = mapping_value(component: component,
199
+ value = mapping_value(component: component,
199
200
  provider_name: mappings_name,
200
201
  value_name: param.mapAttribute,
201
202
  key_name: key_name
@@ -223,10 +224,10 @@ module Highlander
223
224
 
224
225
  if resource_name.nil?
225
226
  # find by component
226
- resource = component.components.find { |c| c.name == component_name }
227
+ resource = component.components.find {|c| c.name == component_name}
227
228
  resource_name = resource.name unless resource.nil?
228
229
  if resource_name.nil?
229
- resource = component.components.find { |c| c.template == component_name }
230
+ resource = component.components.find {|c| c.template == component_name}
230
231
  resource_name = resource.name unless resource.nil?
231
232
  end
232
233
  end
@@ -54,8 +54,12 @@ module Highlander
54
54
  end
55
55
 
56
56
  def Name(name)
57
- @name = name
58
- @config['component_name'] = name
57
+ # nested components always have their name dictated by parent
58
+ # component, defaulting to template name
59
+ if (not @config.key? 'nested_component')
60
+ @name = name
61
+ @config['component_name'] = name
62
+ end
59
63
  end
60
64
 
61
65
  def Description(description)
@@ -78,7 +82,7 @@ module Highlander
78
82
  end
79
83
 
80
84
 
81
- def Component(name:, template:, param_values: {}, config: {}, export_config: {}, &block)
85
+ def Component(template:, name: template, param_values: {}, config: {}, export_config: {}, &block)
82
86
  puts "Initialize #{name} with template #{template}"
83
87
 
84
88
  # load component
@@ -147,7 +151,7 @@ module Highlander
147
151
  def loadComponents()
148
152
 
149
153
  # empty config overrides to start with
150
- @config_overrides = Hash[@components.collect { |c| [c.name, {}] }]
154
+ @config_overrides = Hash[@components.collect { |c| [c.name, {'nested_component' => true}] }]
151
155
  @named_components = Hash[@components.collect { |c| [c.name, c] }]
152
156
 
153
157
  # populate overrides with master config defined overrides
@@ -257,7 +261,11 @@ module Highlander
257
261
  if (@config.key? 'components')
258
262
  @config['components'].each { |component_name, component_config|
259
263
  if component_config.key?('config')
260
- @config_overrides[component_name].extend(component_config['config'])
264
+ if @config_overrides.key? component_name
265
+ @config_overrides[component_name].extend(component_config['config'])
266
+ else
267
+ STDERR.puts("WARN: Overriding config for non-existing component #{component_name}")
268
+ end
261
269
  end
262
270
  }
263
271
  end
@@ -368,9 +376,9 @@ module Highlander
368
376
  build_distribution_url
369
377
  end
370
378
 
371
- def name=(value)
372
- self.Name(value)
373
- end
379
+ # def name=(value)
380
+ # self.Name(value)
381
+ # end
374
382
 
375
383
  def build_distribution_url
376
384
  if not (@distribution_bucket.nil? or @distribution_prefix.nil?)
@@ -406,6 +414,7 @@ def HighlanderComponent(&block)
406
414
 
407
415
  unless @version.nil?
408
416
  instance.version = @version
417
+ instance.config['component_version'] = @version
409
418
  end
410
419
 
411
420
  unless @distribution_bucket.nil?
@@ -415,10 +424,9 @@ def HighlanderComponent(&block)
415
424
  instance.DistributionPrefix(@distribution_prefix)
416
425
  end
417
426
 
427
+ instance.name = @template
418
428
  instance.instance_eval(&block)
419
- if instance.name.nil?
420
- instance.name = @name
421
- end
429
+
422
430
 
423
431
  # load sub-components
424
432
  instance.loadComponents
@@ -18,6 +18,7 @@ module Highlander
18
18
  :cfndsl_content,
19
19
  :mappings,
20
20
  :name,
21
+ :template,
21
22
  :version,
22
23
  :distribution_bucket,
23
24
  :distribution_prefix,
@@ -25,11 +26,14 @@ module Highlander
25
26
  :cfndsl_ext_files,
26
27
  :lambda_src_files
27
28
 
28
- def initialize(component_name, component_dir)
29
+ def initialize(component_template_name,
30
+ component_template_version,
31
+ component_name, component_dir)
32
+ @template = component_template_name
29
33
  @name = component_name
30
34
  @component_dir = component_dir
31
35
  @mappings = {}
32
- @version = nil
36
+ @version = component_template_version
33
37
  @distribution_bucket = nil
34
38
  @distribution_prefix = nil
35
39
  @component_files = []
@@ -65,11 +69,10 @@ module Highlander
65
69
  end
66
70
 
67
71
 
68
- @highlander_dsl_path = "#{@component_dir}/#{@name}.highlander.rb"
69
- @cfndsl_path = "#{@component_dir}/#{@name}.cfndsl.rb"
70
- candidate_config_path = "#{@component_dir}/#{@name}.config.yaml"
72
+ @highlander_dsl_path = "#{@component_dir}/#{@template}.highlander.rb"
73
+ @cfndsl_path = "#{@component_dir}/#{@template}.cfndsl.rb"
71
74
  candidate_mappings_path = "#{@component_dir}/*.mappings.yaml"
72
- candidate_dynamic_mappings_path = "#{@component_dir}/#{@name}.mappings.rb"
75
+ candidate_dynamic_mappings_path = "#{@component_dir}/#{@template}.mappings.rb"
73
76
 
74
77
  @cfndsl_ext_files += Dir["#{@component_dir}/ext/cfndsl/*.rb"]
75
78
  @lambda_src_files += Dir["#{@component_dir}/lambdas/**/*"].find_all {|p| not File.directory? p}
@@ -80,6 +83,7 @@ module Highlander
80
83
 
81
84
  @config.extend config_override unless config_override.nil?
82
85
  @config['component_version'] = @version unless @version.nil?
86
+ @config['component_name'] = @name
83
87
  # allow override of components
84
88
  # config_override.each do |key, value|
85
89
  # @config[key] = value
@@ -101,17 +105,10 @@ module Highlander
101
105
  # 1st pass - parse the file
102
106
  @component_files << @highlander_dsl_path
103
107
  @highlander_dsl = eval(File.read(@highlander_dsl_path), binding)
104
-
105
108
  # set version if not defined
106
109
  @highlander_dsl.ComponentVersion(@version) unless @version.nil?
107
110
 
108
111
 
109
- # Handle name and description defaults if they are not specified
110
- # in template itself
111
- if @highlander_dsl.name.nil?
112
- @highlander_dsl.name = @name
113
- end
114
-
115
112
  if @highlander_dsl.description.nil?
116
113
  @highlander_dsl.Description("#{@highlander_dsl.name} - #{@highlander_dsl.version}")
117
114
  end
@@ -160,46 +157,46 @@ module Highlander
160
157
  @component_sources = component_sources
161
158
  end
162
159
 
163
- def findComponentDefault(component_name, component_version)
160
+ def findTemplateDefault(template_name, component_version)
164
161
  default_lookup_url = 'https://github.com/theonestack'
165
162
  default_lookup_url = ENV['HIGHLANDER_DEFAULT_COMPONENT_GIT_LOOKUP'] if ENV.key? 'HIGHLANDER_DEFAULT_COMPONENT_GIT_LOOKUP'
166
163
 
167
- git_url = "#{default_lookup_url}/hl-component-#{component_name}"
164
+ git_url = "#{default_lookup_url}/hl-component-#{template_name}"
168
165
 
169
166
  if component_version.nil? or component_version.empty? or component_version == 'latest'
170
167
  branch = 'master'
171
168
  else
172
169
  branch = component_version
173
170
  end
174
- local_path = "#{LOCAL_HIGHLANDER_CACHE_LOCATION}/#{component_name}/#{component_version}"
175
- return findComponentGit(local_path, component_name, component_version, git_url, branch)
171
+ local_path = "#{LOCAL_HIGHLANDER_CACHE_LOCATION}/#{template_name}/#{component_version}"
172
+ return findTemplateGit(local_path, template_name, component_version, git_url, branch)
176
173
 
177
174
  end
178
175
 
179
- def findComponentGit(local_path, component_name, component_version, git_url, branch)
176
+ def findTemplateGit(cache_path, component_name, component_version, git_url, branch)
180
177
  begin
181
- local_path = "#{local_path}/" unless local_path.end_with? '/'
178
+ cache_path = "#{cache_path}/" unless cache_path.end_with? '/'
182
179
  # if this is snapshot, clean local cache
183
180
  if branch.end_with? '.snapshot'
184
181
  branch = branch.gsub('.snapshot', '')
185
- FileUtils.rmtree local_path if File.exist? local_path and File.directory? local_path
182
+ FileUtils.rmtree cache_path if File.exist? cache_path and File.directory? cache_path
186
183
  end
187
184
 
188
185
  # if local cache exists, return from cache
189
- if not Dir.glob("#{local_path}*.highlander.rb").empty?
186
+ if not Dir.glob("#{cache_path}*.highlander.rb").empty?
190
187
  # if cache exists, just return from cache
191
- component_name = Dir.glob("#{local_path}*.highlander.rb")[0].gsub(local_path, '').gsub('.highlander.rb','')
192
- return component_name, local_path
188
+ component_name = Dir.glob("#{cache_path}*.highlander.rb")[0].gsub(cache_path, '').gsub('.highlander.rb', '')
189
+ return component_name, cache_path
193
190
  end
194
191
 
195
192
  # shallow clone
196
193
  puts "Trying to load #{component_name}/#{component_version} from #{git_url}##{branch} ... "
197
194
  clone_opts = { depth: 1 }
198
195
  clone_opts[:branch] = branch if not (branch.nil? or branch.empty?)
199
- Git.clone git_url, local_path, clone_opts
200
- puts "\t .. cached in #{local_path}\n"
196
+ Git.clone git_url, cache_path, clone_opts
197
+ puts "\t .. cached in #{cache_path}\n"
201
198
  # return from cache once it's cloned
202
- return findComponentGit(local_path, component_name, component_version, git_url, branch)
199
+ return findTemplateGit(cache_path, component_name, component_version, git_url, branch)
203
200
  rescue Exception => e
204
201
  STDERR.puts "Failed to resolve component #{component_name}@#{component_version} from #{git_url}"
205
202
  STDERR.puts e
@@ -207,7 +204,7 @@ module Highlander
207
204
  end
208
205
  end
209
206
 
210
- def findComponentS3(s3_location, component_name, component_version)
207
+ def findTemplateS3(s3_location, component_name, component_version)
211
208
  parts = s3_location.split('/')
212
209
  bucket = parts[2]
213
210
  prefix = parts[3]
@@ -243,42 +240,44 @@ module Highlander
243
240
  end
244
241
  end
245
242
 
246
- def findComponentGitTemplate(component_name, component_version)
247
- if component_name.include? '#'
248
- parts = component_name.split('#')
249
- component_name = parts[0]
250
- component_version = parts[1]
243
+ # will try and locate template based on git template location
244
+ # if template location is not git repo, returns nil
245
+ def tryFindTemplateGit(template_location, template_version)
246
+ if template_location.include? '#'
247
+ parts = template_location.split('#')
248
+ template_location = parts[0]
249
+ template_version = parts[1]
251
250
  end
252
251
 
253
252
  # avoid any nres
254
- component_version = '' if component_version.nil?
253
+ template_version = '' if template_version.nil?
255
254
 
256
255
  # if empty or latest branch is empty
257
- if component_version.empty? or component_version == 'latest' or component_version == 'latest.snapshot'
256
+ if template_version.empty? or template_version == 'latest' or template_version == 'latest.snapshot'
258
257
  branch = ''
259
258
  else
260
259
  # otherwise component version is actual branch
261
- branch = component_version
260
+ branch = template_version
262
261
  end
263
262
 
264
263
 
265
264
  git_url = nil
266
- if component_name.start_with? 'git:'
267
- git_url = component_name.gsub('git:', '')
268
- elsif component_name.start_with? 'github:'
269
- git_url = "https://github.com/#{component_name.gsub('github:', '')}"
270
- elsif component_name.start_with? 'github.com:'
271
- git_url = "https://github.com/#{component_name.gsub('github.com:', '')}"
265
+ if template_location.start_with? 'git:'
266
+ git_url = template_location.gsub('git:', '')
267
+ elsif template_location.start_with? 'github:'
268
+ git_url = "https://github.com/#{template_location.gsub('github:', '')}"
269
+ elsif template_location.start_with? 'github.com:'
270
+ git_url = "https://github.com/#{template_location.gsub('github.com:', '')}"
272
271
  end
273
272
 
274
- local_path = "#{LOCAL_HIGHLANDER_CACHE_LOCATION}/#{component_name}/#{component_version}"
273
+ local_path = "#{LOCAL_HIGHLANDER_CACHE_LOCATION}/#{template_location}/#{template_version}"
275
274
 
276
275
  if not git_url.nil?
277
- component_name, location = findComponentGit(local_path, component_name, component_version, git_url, branch)
276
+ template_name, location = findTemplateGit(local_path, template_location, template_version, git_url, branch)
278
277
  if location.nil?
279
- raise "Could not resolve component #{component_name}@#{component_version}"
278
+ raise "Could not resolve component #{template_location}@#{template_version}"
280
279
  else
281
- return component_name, location
280
+ return template_name, template_version, location
282
281
  end
283
282
  end
284
283
 
@@ -287,69 +286,74 @@ module Highlander
287
286
 
288
287
  # Find component and given list of sources
289
288
  # @return [Highlander::Factory::Component]
290
- def findComponent(component_name, component_version = nil)
289
+ def loadComponentFromTemplate(template_name, template_version = nil, component_name = nil)
291
290
 
292
- component_version_s = component_version.nil? ? 'latest' : component_version
293
- component_version = nil if component_version == 'latest'
291
+ component_version_s = template_version.nil? ? 'latest' : template_version
292
+ template_version = nil if template_version == 'latest'
293
+ component_name = template_name if component_name.nil?
294
294
 
295
- if component_name.include? '@' and (not component_name.start_with? 'git')
296
- parts = component_name.split('@')
297
- component_name = parts[0]
298
- component_version = parts[1]
295
+ if template_name.include? '@' and (not template_name.start_with? 'git')
296
+ parts = template_name.split('@')
297
+ template_name = parts[0]
298
+ template_version = parts[1]
299
+ component_version_s = template_version
299
300
  end
300
301
 
301
302
  # if component specified as git location
302
- new_name, candidate_git = findComponentGitTemplate(component_name, component_version_s)
303
- return buildComponent(new_name, candidate_git) unless candidate_git.nil?
303
+ new_template_name, new_version, candidate_git = tryFindTemplateGit(template_name, component_version_s)
304
+ return buildComponentFromLocation(new_template_name, new_version, component_name, candidate_git) unless candidate_git.nil?
304
305
 
305
306
  # if not git but has .snapshot lookup in default
306
- if (not component_version.nil?) and component_version.end_with? '.snapshot'
307
- new_name, default_candidate = findComponentDefault(component_name, component_version_s)
308
- return buildComponent(new_name, default_candidate) unless default_candidate.nil?
307
+ if (not template_version.nil?) and template_version.end_with? '.snapshot'
308
+ new_template_name, default_candidate = findTemplateDefault(template_name, component_version_s)
309
+ return buildComponentFromLocation(new_template_name, template_version, component_name, default_candidate) unless default_candidate.nil?
309
310
  end
310
311
 
311
312
  # try in all of the component source
312
313
  @component_sources.each do |source|
313
- component_full_name = "#{component_name}@#{component_version.nil? ? 'latest' : component_version}"
314
+ component_full_name = "#{template_name}@#{template_version.nil? ? 'latest' : template_version}"
314
315
  # TODO handle http(s) sources and their download to local
315
316
  if source.start_with?('http')
316
317
  raise StandardError, 'http(s) sources not supported yet'
317
318
  elsif source.start_with?('s3://')
318
319
  # s3 candidate
319
320
 
320
- s3_candidate = findComponentS3(source, component_name, component_version_s)
321
+ s3_candidate = findTemplateS3(source, template_name, component_version_s)
321
322
  if not s3_candidate.nil?
322
323
  # at this point all component files are download to local file system and consumed from there
323
- return buildComponent(component_name, s3_candidate)
324
+ return buildComponentFromLocation(template_name, template_version, component_name, s3_candidate)
324
325
  end
325
326
 
326
327
  else
327
328
  # file system candidate
328
- candidate = "#{source}/#{component_name}"
329
- candidate = "#{candidate}/#{component_version}" unless component_version.nil?
330
- candidate_hl_path = "#{candidate}/#{component_name}.highlander.rb"
331
- candidate2_hl_path = "#{source}/#{component_name}.highlander.rb"
329
+ candidate = "#{source}/#{template_name}"
330
+ candidate = "#{candidate}/#{template_version}" unless template_version.nil?
331
+ candidate_hl_path = "#{candidate}/#{template_name}.highlander.rb"
332
+ candidate2_hl_path = "#{source}/#{template_name}.highlander.rb"
332
333
  puts "Trying to load #{component_full_name} from #{candidate} ... "
333
334
  if File.exist?(candidate_hl_path)
334
- return buildComponent(component_name, candidate)
335
+ return buildComponentFromLocation(template_name, template_version, component_name, candidate)
335
336
  end
336
337
  puts "Trying to load #{component_full_name} from #{source} ... "
337
338
  if File.exist?(candidate2_hl_path)
338
- return buildComponent(component_name, source)
339
+ return buildComponentFromLocation(template_name, template_version, component_name, source)
339
340
  end unless component_version_s != 'latest'
340
341
  end
341
342
  end
342
343
 
343
344
  # try default component source on github
344
- component_name, default_candidate = findComponentDefault(component_name, component_version_s)
345
- return buildComponent(component_name, default_candidate) unless default_candidate.nil?
345
+ template_name, default_candidate = findTemplateDefault(template_name, component_version_s)
346
+ return buildComponentFromLocation(template_name, template_version, component_name, default_candidate) unless default_candidate.nil?
346
347
 
347
- raise StandardError, "highlander template #{component_name}@#{component_version_s} not located" +
348
+ raise StandardError, "highlander template #{template_name}@#{component_version_s} not located" +
348
349
  " in sources #{@component_sources}"
349
350
  end
350
351
 
351
- def buildComponent(component_name, component_dir)
352
- component = Component.new(component_name, component_dir)
352
+ def buildComponentFromLocation(template_name,
353
+ template_version,
354
+ component_name,
355
+ template_location)
356
+ component = Component.new(template_name, template_version, component_name, template_location)
353
357
  component.load_config
354
358
  return component
355
359
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfhighlander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1.alpha.27
4
+ version: 0.2.1.alpha.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikola Tosic
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-01 00:00:00.000000000 Z
12
+ date: 2018-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline