cfhighlander 0.2.1.alpha.43 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- module Cfhighlander
1
+ module Highlander
2
2
 
3
3
 
4
4
  module Helper
@@ -11,7 +11,7 @@ module Cfhighlander
11
11
  end
12
12
 
13
13
  if value.class == Hash
14
- return value.to_json
14
+ return value.to_s
15
15
  end
16
16
 
17
17
  return "'#{value}'"
@@ -1,4 +1,4 @@
1
- module Cfhighlander
1
+ module Highlander
2
2
 
3
3
  ### Map Providers provide predefined maps or list of maps
4
4
  ### Aside from predefined mappings from providers
@@ -1,11 +1,11 @@
1
- require_relative './cfhighlander.compiler'
1
+ require_relative './highlander.compiler'
2
2
  require 'aws-sdk-s3'
3
3
 
4
- module Cfhighlander
4
+ module Highlander
5
5
 
6
6
  module Publisher
7
7
 
8
- class ComponentPublisher
8
+ class Component
9
9
 
10
10
  def initialize(component, cleanup)
11
11
  @component = component
@@ -2,7 +2,7 @@ require 'aws-sdk-cloudformation'
2
2
  require 'aws-sdk-s3'
3
3
  require 'digest/md5'
4
4
 
5
- module Cfhighlander
5
+ module Highlander
6
6
 
7
7
  module Cloudformation
8
8
 
data/lib/util/zip.util.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'zip'
2
2
 
3
3
 
4
- module Cfhighlander
4
+ module Highlander
5
5
  module Util
6
6
  ###
7
7
  ### taken from https://github.com/rubyzip/rubyzip/tree/master/samples
@@ -8,7 +8,7 @@ CloudFormation do
8
8
  <% end %>
9
9
 
10
10
  # render subcomponents
11
- <% for @component in dsl.subcomponents %>
11
+ <% for @component in dsl.components %>
12
12
  CloudFormation_Stack('<%= @component.name.gsub('-','').gsub('_','') %>') do
13
13
  TemplateURL '<%= @component.distribution_url %>'
14
14
  Parameters ({
@@ -38,9 +38,6 @@ CloudFormation do
38
38
  <% unless @param.no_echo.nil? %>
39
39
  NoEcho <%= @param.no_echo.to_s %>
40
40
  <% end %>
41
- <% unless @param.allowed_values.nil? %>
42
- AllowedValues <%= @param.allowed_values.to_s %>
43
- <% end %>
44
41
  end
45
42
  <% end %>
46
43
 
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.43
4
+ version: 0.2.1
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-07 00:00:00.000000000 Z
12
+ date: 2018-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
@@ -191,26 +191,6 @@ dependencies:
191
191
  - - "<"
192
192
  - !ruby/object:Gem::Version
193
193
  version: '2'
194
- - !ruby/object:Gem::Dependency
195
- name: netaddr
196
- requirement: !ruby/object:Gem::Requirement
197
- requirements:
198
- - - "~>"
199
- - !ruby/object:Gem::Version
200
- version: '1.5'
201
- - - ">="
202
- - !ruby/object:Gem::Version
203
- version: 1.5.1
204
- type: :runtime
205
- prerelease: false
206
- version_requirements: !ruby/object:Gem::Requirement
207
- requirements:
208
- - - "~>"
209
- - !ruby/object:Gem::Version
210
- version: '1.5'
211
- - - ">="
212
- - !ruby/object:Gem::Version
213
- version: 1.5.1
214
194
  - !ruby/object:Gem::Dependency
215
195
  name: rspec
216
196
  requirement: !ruby/object:Gem::Requirement
@@ -234,7 +214,7 @@ extra_rdoc_files: []
234
214
  files:
235
215
  - README.md
236
216
  - bin/cfhighlander
237
- - bin/cfhighlander.rb
217
+ - bin/highlander.rb
238
218
  - cfndsl_ext/config/managed_policies.yaml
239
219
  - cfndsl_ext/iam_helper.rb
240
220
  - cfndsl_ext/lambda_helper.rb
@@ -243,19 +223,16 @@ files:
243
223
  - hl_ext/common_helper.rb
244
224
  - hl_ext/mapping_helper.rb
245
225
  - hl_ext/vpc.rb
246
- - lib/cfhighlander.compiler.rb
247
- - lib/cfhighlander.dsl.base.rb
248
- - lib/cfhighlander.dsl.params.rb
249
- - lib/cfhighlander.dsl.subcomponent.rb
250
- - lib/cfhighlander.dsl.template.rb
251
- - lib/cfhighlander.factory.rb
252
- - lib/cfhighlander.factory.templatefinder.rb
253
- - lib/cfhighlander.helper.rb
254
- - lib/cfhighlander.mapproviders.rb
255
- - lib/cfhighlander.model.component.rb
256
- - lib/cfhighlander.model.templatemeta.rb
257
- - lib/cfhighlander.publisher.rb
258
- - lib/cfhighlander.validator.rb
226
+ - lib/highlander.compiler.rb
227
+ - lib/highlander.dsl.base.rb
228
+ - lib/highlander.dsl.component.rb
229
+ - lib/highlander.dsl.params.rb
230
+ - lib/highlander.dsl.rb
231
+ - lib/highlander.factory.rb
232
+ - lib/highlander.helper.rb
233
+ - lib/highlander.mapproviders.rb
234
+ - lib/highlander.publisher.rb
235
+ - lib/highlander.validator.rb
259
236
  - lib/util/zip.util.rb
260
237
  - templates/cfndsl.component.template.erb
261
238
  homepage: https://github.com/theonestack/cfhighlander/blob/master/README.md
@@ -273,9 +250,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
273
250
  version: '0'
274
251
  required_rubygems_version: !ruby/object:Gem::Requirement
275
252
  requirements:
276
- - - ">"
253
+ - - ">="
277
254
  - !ruby/object:Gem::Version
278
- version: 1.3.1
255
+ version: '0'
279
256
  requirements: []
280
257
  rubyforge_project:
281
258
  rubygems_version: 2.7.7
@@ -1,108 +0,0 @@
1
- require_relative './cfhighlander.dsl.base'
2
-
3
- module Cfhighlander
4
-
5
- module Dsl
6
-
7
- # dsl statements
8
- class Parameters < DslBase
9
-
10
- attr_accessor :param_list
11
-
12
- def initialize()
13
- @param_list = []
14
- end
15
-
16
- def addParam(param)
17
- existing_param = @param_list.find {|p| p.name == param.name}
18
- if not existing_param.nil?
19
- puts "Parameter being overwritten. Updating parameter #{param.name} with new definition..."
20
- @param_list[@param_list.index(existing_param)] = param
21
- else
22
- @param_list << param
23
- end
24
- end
25
-
26
- def StackParam(name, defaultValue = '', isGlobal: false, noEcho: false, type: 'String')
27
- STDERR.puts "DEPRECATED: StackParam #{name} - Use ComponentParam instead"
28
- ComponentParam(name, defaultValue, isGlobal: isGlobal, noEcho: noEcho, type: type)
29
- end
30
-
31
- def OutputParam(component:, name:, isGlobal: false, noEcho: false, type: 'String')
32
- STDERR.puts ("DEPRECATED: OutputParam #{name} - Use ComponentParam instead. Outputut params are " +
33
- "autorwired by name only, with component disregarded")
34
- param = ComponentParam(name, '', isGlobal: isGlobal, noEcho: noEcho, type: type)
35
- param.provided_value = "#{component}.#{name}"
36
- end
37
-
38
- def ComponentParam(name, defaultValue = '', isGlobal: false, noEcho: false, type: 'String', allowedValues: nil)
39
- param = Parameter.new(name, type, defaultValue, noEcho, isGlobal, allowedValues)
40
- param.config = @config
41
- addParam param
42
- return param
43
- end
44
-
45
- def MappingParam(name, defaultValue = '', &block)
46
- param = MappingParam.new(name, 'String', defaultValue)
47
- param.config = @config
48
- param.instance_eval(&block)
49
- addParam param
50
- end
51
-
52
-
53
- end
54
-
55
- # model classes
56
- class Parameter < DslBase
57
- attr_accessor :name,
58
- :type,
59
- :default_value,
60
- :no_echo,
61
- :is_global,
62
- :provided_value,
63
- :allowed_values
64
-
65
- def initialize(name, type, defaultValue, noEcho = false, isGlobal = false, allowed_values = nil)
66
- @no_echo = noEcho
67
- @name = name
68
- @type = type
69
- @default_value = defaultValue
70
- @is_global = isGlobal
71
- @allowed_values = allowed_values
72
- @provided_value = nil
73
- end
74
-
75
- end
76
-
77
- class MappingParam < Parameter
78
-
79
- attr_accessor :mapName, :mapKey, :mapAttribute
80
-
81
- def method_missing(method, *args)
82
- smethod = "#{method}"
83
- if smethod.start_with?('Map')
84
- puts smethod
85
- end
86
-
87
- super.method_missing(method)
88
- end
89
-
90
- def key(map_key)
91
- @mapKey = map_key
92
- end
93
-
94
- def attribute(key)
95
- @mapAttribute = key
96
- end
97
-
98
- def map(mapName)
99
- @mapName = mapName
100
- end
101
-
102
- def mapProvider
103
- mappings_provider(@mapName)
104
- end
105
-
106
- end
107
- end
108
- end
@@ -1,45 +0,0 @@
1
- require_relative './cfhighlander.dsl.template'
2
- require_relative './cfhighlander.factory.templatefinder'
3
- require_relative './cfhighlander.model.component'
4
- require 'fileutils'
5
- require 'git'
6
-
7
-
8
- module Cfhighlander
9
-
10
- module Factory
11
-
12
- class ComponentFactory
13
-
14
- attr_accessor :component_sources
15
-
16
- def initialize(component_sources = [])
17
- @template_finder = Cfhighlander::Factory::TemplateFinder.new(component_sources)
18
- @component_sources = component_sources
19
- end
20
-
21
- # Find component and given list of sources
22
- # @return [Cfhighlander::Factory::Component]
23
- def loadComponentFromTemplate(template_name, template_version = nil, component_name = nil)
24
-
25
- template_meta = @template_finder.findTemplate(template_name, template_version)
26
-
27
- raise StandardError, "highlander template #{template_name}@#{template_version} not located" +
28
- " in sources #{@component_sources}" if template_meta.nil?
29
-
30
- component_name = template_name if component_name.nil?
31
- return buildComponentFromLocation(template_meta, component_name)
32
-
33
- end
34
-
35
-
36
- def buildComponentFromLocation(template_meta, component_name)
37
- component = Model::Component.new(template_meta, component_name)
38
- component.load_config
39
- return component
40
- end
41
-
42
- end
43
- end
44
-
45
- end
@@ -1,248 +0,0 @@
1
- LOCAL_CFHIGHLANDER_CACHE_LOCATION = "#{ENV['HOME']}/.cfhighlander/components"
2
-
3
- require_relative './cfhighlander.model.templatemeta'
4
-
5
- module Cfhighlander
6
-
7
- module Factory
8
-
9
- class TemplateFinder
10
-
11
- def initialize(component_sources = [])
12
- ## First look in local $PWD/components folder
13
- ## Then search for cached $HOME/.highlander/components
14
- ## Then search in sources given by dsl
15
- default_locations = [
16
- LOCAL_CFHIGHLANDER_CACHE_LOCATION,
17
- File.expand_path('components'),
18
- File.expand_path('.')
19
- ]
20
- default_locations.each do |predefined_path|
21
- component_sources.unshift(predefined_path)
22
- end
23
-
24
- @component_sources = component_sources
25
- end
26
-
27
- def findTemplateDefault(template_name, component_version)
28
- default_lookup_url = 'https://github.com/theonestack'
29
- default_lookup_url = ENV['HIGHLANDER_DEFAULT_COMPONENT_GIT_LOOKUP'] if ENV.key? 'HIGHLANDER_DEFAULT_COMPONENT_GIT_LOOKUP'
30
- default_lookup_url = ENV['CFHIGHLANDER_DEFAULT_COMPONENT_GIT_LOOKUP'] if ENV.key? 'CFHIGHLANDER_DEFAULT_COMPONENT_GIT_LOOKUP'
31
-
32
- git_url = "#{default_lookup_url}/hl-component-#{template_name}"
33
-
34
- if component_version.nil? or component_version.empty? or component_version == 'latest'
35
- branch = 'master'
36
- else
37
- branch = component_version
38
- end
39
- local_path = "#{LOCAL_CFHIGHLANDER_CACHE_LOCATION}/#{template_name}/#{component_version}"
40
- return findTemplateGit(local_path, template_name, component_version, git_url, branch)
41
-
42
- end
43
-
44
- def findTemplateGit(cache_path, component_name, component_version, git_url, branch)
45
- begin
46
- cache_path = "#{cache_path}/" unless cache_path.end_with? '/'
47
- # if this is snapshot, clean local cache
48
- if branch.end_with? '.snapshot'
49
- branch = branch.gsub('.snapshot', '')
50
- FileUtils.rmtree cache_path if File.exist? cache_path and File.directory? cache_path
51
- end
52
-
53
- # if local cache exists, return from cache
54
- if not Dir.glob("#{cache_path}*.highlander.rb").empty?
55
- # if cache exists, just return from cache
56
- component_name = Dir.glob("#{cache_path}*.highlander.rb")[0].gsub(cache_path, '').gsub('.highlander.rb', '')
57
- STDERR.puts("DEPRECATED: #{component_name}: Use *.cfhighlander.rb template file name pattern")
58
- return component_name, cache_path
59
- end
60
-
61
- if not Dir.glob("#{cache_path}*.cfhighlander.rb").empty?
62
- # if cache exists, just return from cache
63
- component_name = Dir.glob("#{cache_path}*.cfhighlander.rb")[0].gsub(cache_path, '').gsub('.highlander.rb', '')
64
- return component_name, cache_path
65
- end
66
-
67
- # shallow clone
68
- puts "Trying to load #{component_name}/#{component_version} from #{git_url}##{branch} ... "
69
- clone_opts = { depth: 1 }
70
- clone_opts[:branch] = branch if not (branch.nil? or branch.empty?)
71
- Git.clone git_url, cache_path, clone_opts
72
- puts "\t .. cached in #{cache_path}\n"
73
- # return from cache once it's cloned
74
- return findTemplateGit(cache_path, component_name, component_version, git_url, branch)
75
- rescue Exception => e
76
- STDERR.puts "Failed to resolve component #{component_name}@#{component_version} from #{git_url}"
77
- STDERR.puts e
78
- return nil
79
- end
80
- end
81
-
82
- def findTemplateS3(s3_location, component_name, component_version, use_legacy_extension = true)
83
- parts = s3_location.split('/')
84
- bucket = parts[2]
85
- prefix = parts[3]
86
- s3_key = "#{prefix}/#{component_name}/#{component_version}/#{component_name}.highlander.rb"
87
- s3_prefix = "#{prefix}/#{component_name}/#{component_version}/"
88
- local_destination = "#{LOCAL_CFHIGHLANDER_CACHE_LOCATION}/#{component_name}/#{component_version}"
89
- begin
90
- s3 = Aws::S3::Client.new({ region: s3_bucket_region(bucket) })
91
- FileUtils.mkdir_p local_destination unless Dir.exist? local_destination
92
-
93
- hl_content = s3.get_object({ bucket: bucket,
94
- key: s3_key,
95
- response_target: "#{local_destination}/#{component_name}.#{use_legacy_extension ? 'highlander' : 'cfhighlander'}.rb"
96
- })
97
- # if code execution got so far we consider file exists and download it locally
98
- component_files = s3.list_objects_v2({ bucket: bucket, prefix: s3_prefix })
99
- component_files.contents.each {|s3_object|
100
- file_name = s3_object.key.gsub(s3_prefix, '')
101
- destination_file = "#{local_destination}/#{file_name}"
102
- destination_dir = File.dirname(destination_file)
103
- print "Caching #{file_name} of #{component_name}@#{component_version} in #{destination_dir} ... "
104
-
105
- FileUtils.mkpath(destination_dir) unless File.exists?(destination_dir)
106
- s3.get_object({ bucket: bucket, key: s3_object.key, response_target: destination_file })
107
- print " [OK] \n"
108
- }
109
- if use_legacy_extension
110
- STDERR.puts "DEPRECATED: s3 load #{component_name} with *.highlander.rb template file name pattern"
111
- end
112
- return local_destination
113
- rescue => e
114
- # this handles both nonexisting key and bucket
115
- if use_legacy_extension
116
- return findTemplateS3(s3_location, component_name, component_version, false)
117
- end
118
- puts("#{component_name} not found in s3://#{bucket}/#{prefix}")
119
- STDERR.puts(e.to_s) unless e.message.include? 'does not exist'
120
- return nil
121
- end
122
- end
123
-
124
- # will try and locate template based on git template location
125
- # if template location is not git repo, returns nil
126
- def tryFindTemplateGit(template_location, template_version)
127
-
128
- # avoid any nres
129
- template_version = '' if template_version.nil?
130
-
131
- # if empty or latest branch is empty
132
- if template_version.empty? or template_version == 'latest' or template_version == 'latest.snapshot'
133
- branch = ''
134
- else
135
- # otherwise component version is actual branch
136
- branch = template_version
137
- end
138
-
139
-
140
- git_url = nil
141
- if template_location.start_with? 'git:'
142
- git_url = template_location.gsub('git:', '')
143
- elsif template_location.start_with? 'github:'
144
- git_url = "https://github.com/#{template_location.gsub('github:', '')}"
145
- elsif template_location.start_with? 'github.com:'
146
- git_url = "https://github.com/#{template_location.gsub('github.com:', '')}"
147
- end
148
-
149
-
150
- if not git_url.nil?
151
- local_path = "#{LOCAL_CFHIGHLANDER_CACHE_LOCATION}/#{template_location.gsub(':', '_').gsub(/\/+/, '/')}/#{template_version}"
152
- template_name, location = findTemplateGit(local_path, template_location, template_version, git_url, branch)
153
- if location.nil?
154
- raise "Could not resolve component #{template_location}@#{template_version}"
155
- else
156
- return template_name, template_version, location
157
- end
158
- end
159
-
160
- return nil
161
- end
162
-
163
- def findTemplate(template_name, template_version)
164
- template_version_s = template_version.nil? ? 'latest' : template_version
165
- template_version = nil if template_version == 'latest'
166
- is_git_template = template_name.start_with? 'git'
167
-
168
- if template_name.include? '@' and (not template_name.start_with? 'git')
169
- parts = template_name.split('@')
170
- template_name = parts[0]
171
- template_version = parts[1]
172
- template_version_s = template_version
173
- end
174
-
175
- if template_name.include? '#' and (is_git_template)
176
- parts = template_name.split('#')
177
- template_name = parts[0]
178
- template_version = parts[1]
179
- template_version_s = template_version
180
- end
181
-
182
- # if component specified as git location
183
- if is_git_template
184
- new_template_name, new_version, candidate_git = tryFindTemplateGit(template_name, template_version_s)
185
- return build_meta(new_template_name, new_version, candidate_git) unless candidate_git.nil?
186
- end
187
-
188
- # if not git but has .snapshot lookup in default, it is allowed to reference default
189
- # snapshots
190
- if (not template_version.nil?) and template_version.end_with? '.snapshot'
191
- new_template_name, snapshot_candidate_location = findTemplateDefault(template_name, template_version_s)
192
- return build_meta(new_template_name, template_version, snapshot_candidate_location) unless snapshot_candidate_location.nil?
193
- end
194
-
195
- # try in all of the component sources
196
- @component_sources.each do |source|
197
- template_full_name = "#{template_name}@#{template_version.nil? ? 'latest' : template_version}"
198
- # TODO handle http(s) sources and their download to local
199
- if source.start_with?('http')
200
- raise StandardError, 'http(s) sources not supported yet'
201
- elsif source.start_with?('s3://')
202
- # s3 candidate
203
-
204
- s3_candidate = findTemplateS3(source, template_name, template_version_s)
205
- # at this point all component files are download to local file system and consumed from there
206
- return build_meta(template_name, template_version_s, s3_candidate) unless s3_candidate.nil?
207
-
208
- else
209
- # file system candidate
210
- candidate = "#{source}/#{template_name}"
211
- candidate = "#{candidate}/#{template_version}" unless template_version.nil?
212
- candidate_hl_path = "#{candidate}/#{template_name}.highlander.rb"
213
- candidate_cfhl_path = "#{candidate}/#{template_name}.cfhighlander.rb"
214
- candidate2_hl_path = "#{source}/#{template_name}.highlander.rb"
215
- candidate2_cfhl_path = "#{source}/#{template_name}.cfhighlander.rb"
216
- puts "TRACE: Trying to load #{template_full_name} from #{candidate} ... "
217
- if (File.exist?(candidate_hl_path) or File.exist?(candidate_cfhl_path))
218
- return build_meta(template_name, template_version_s, candidate)
219
- end
220
-
221
- puts "TRACE: Trying to load #{template_full_name} from #{source} ... "
222
- # if component version is latest it is allowed to search in path
223
- # with no version component in it
224
- if (File.exist?(candidate2_hl_path) or File.exist?(candidate2_cfhl_path))
225
- return build_meta(template_name, 'latest', source)
226
- end unless template_version_s != 'latest'
227
- end
228
- end
229
-
230
- # try default component source on github
231
- template_name, default_candidate = findTemplateDefault(template_name, template_version_s)
232
- return build_meta(template_name, template_version_s, default_candidate) unless default_candidate.nil?
233
-
234
- return nil
235
- end
236
-
237
- def build_meta(template_name, template_version, template_location)
238
- return Cfhighlander::Model::TemplateMetadata.new(
239
- template_name: template_name,
240
- template_version: template_version,
241
- template_location: template_location)
242
- end
243
-
244
- end
245
-
246
- end
247
-
248
- end