cloudformation-tool 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b44f3ef0d04f6c9f0329d1e081a529ce1cfdd3e8b2da7c85be51b224957faae
4
- data.tar.gz: d43a5b5968ae31fd7b3969a45a3c09814f91dcbcc6e39e9a6fb3b30444d9a031
3
+ metadata.gz: 3cabf54063c7c094f182862caac32e359c495e0a8d45bac807b0bef972cc090c
4
+ data.tar.gz: a46b8080f9d6cdd042d604b70cc189ea41b0a1cb2b77ba77055fa52635e4995c
5
5
  SHA512:
6
- metadata.gz: 062c2685822c31422a64356af5b2e4197d3436401d94528c0cede97ab94774c565c83da36937fb532c2133fd3a67fa6cb5c7d248b7ad89a622a5f05794e6731c
7
- data.tar.gz: 79c31fdf1bc03b52a0864ee4f9cfe325a2036800bae3cae2e473d8b67f7ad64373d2720c0849518c38e3403662dc7129a32312dbb5aecf22e0356770bcb28927
6
+ metadata.gz: b9d2d2334c8d8b242595523b7fb233b2bba9060b9ba68d8efbc1ee2516bcd5793752898682ce20a00dd7980c0f3b370bd4c82d39ef7c588ea35c2761a71af589
7
+ data.tar.gz: 57f3ec6288140dc0343b24074b670fb7a7fab1ae179418fc7f70cdb8a88e444c6e294ec919ee58a12f8cd1c67649cd20de987bc2d254e31313356cb630310e29
@@ -81,6 +81,16 @@ module CloudFormationTool
81
81
  return data
82
82
  end
83
83
  end
84
+
85
+ def embed_includes_future
86
+ (@data.delete(@data.keys.find{|k| k.start_with? 'Include'}) || []).each do |path|
87
+ case path
88
+ when Hash
89
+ when String
90
+ embed_included_path path
91
+ end
92
+ end
93
+ end
84
94
 
85
95
  def embed_includes
86
96
  (@data.delete(@data.keys.find{|k| k.start_with? 'Include'}) || []).each do |path|
@@ -169,7 +179,7 @@ module CloudFormationTool
169
179
  end
170
180
  when 'AWS::Lambda::Function'
171
181
  if key == 'Code'
172
- LambdaCode.new(val, self).to_cloudformation
182
+ LambdaCode.new(val, self, data['Runtime']).to_cloudformation
173
183
  else
174
184
  load_files(val, restype)
175
185
  end
@@ -7,33 +7,62 @@ module CloudFormationTool
7
7
  class LambdaCode
8
8
  include Storable
9
9
 
10
- def initialize(code, tpl)
10
+ def initialize(code, tpl, runtime = nil)
11
+ @tpl = tpl
12
+ @zipfile_safe = runtime.to_s.match(%r{^(nodejs|python)}) != nil
11
13
  @data = code
12
14
  @data['Url'] = @data.delete 'URL' if @data.key? 'URL' # normalize to CF convention if seeing old key
13
15
  if @data.key? 'Url'
14
- debug "Trying Lambda code from #{@data['Url']}"
15
- @data['Url'] = url = tpl.resolveVal(@data['Url'])
16
- return unless url.is_a? String
17
- log "Downloading Lambda code from #{url}"
18
- if already_in_cache(url)
19
- debug "Reusing remote cached object instead of downloading"
20
- else
21
- res = fetch_from_url(url)
22
- @s3_url = URI(upload(make_filename(url.split('.').last), res.body, mime_type: res['content-type'], gzip: false))
23
- log "uploaded Lambda function to #{@s3_url}"
24
- end
16
+ handl_url
25
17
  elsif @data.key? 'Path'
26
- @data['Path'] = path = tpl.resolveVal(@data['Path'])
27
- return unless path.is_a? String
28
- debug "Reading Lambda code from #{path}"
29
- path = if path.start_with? "/" then path else "#{tpl.basedir}/#{path}" end
30
- if File.directory?(path)
31
- @s3_url = URI(upload(make_filename('zip'), zip_path(path), mime_type: 'application/zip', gzip: false))
32
- log "uploaded Lambda function to #{@s3_url}"
33
- else # Convert files to ZipFile
34
- @data.delete 'Path'
35
- @data['ZipFile'] = File.read(path)
18
+ handle_path
19
+ end
20
+ end
21
+
22
+ def handle_url
23
+ debug "Trying Lambda code from #{@data['Url']}"
24
+ @data['Url'] = url = @tpl.resolveVal(@data['Url'])
25
+ return unless url.is_a? String
26
+ log "Downloading Lambda code from #{url}"
27
+ if already_in_cache(url)
28
+ debug "Reusing remote cached object instead of downloading"
29
+ else
30
+ res = fetch_from_url(url)
31
+ @s3_url = URI(upload(make_filename(url.split('.').last), res.body, mime_type: res['content-type'], gzip: false))
32
+ log "uploaded Lambda function to #{@s3_url}"
33
+ end
34
+ end
35
+
36
+ def handle_path
37
+ @data['Path'] = path = @tpl.resolveVal(@data['Path'])
38
+ return unless path.is_a? String
39
+ debug "Reading Lambda code from #{path}"
40
+ path = if path.start_with? "/" then path else "#{@tpl.basedir}/#{path}" end
41
+ if File.directory?(path)
42
+ @s3_url = URI(upload(make_filename('zip'), zip_path(path), mime_type: 'application/zip', gzip: false))
43
+ log "uploaded Lambda function to #{@s3_url}"
44
+ else
45
+ handle_file path
46
+ end
47
+ end
48
+
49
+ def handle_file(path)
50
+ @data.delete 'Path'
51
+ contents = File.read(path)
52
+ if contents.size <= 4096 and @zipfile_safe # Convert files to ZipFile
53
+ @data['ZipFile'] = contents
54
+ else # upload and hope for the best
55
+ ext = path.split('.').last
56
+ ctype = case ext
57
+ when 'jar'
58
+ 'application/java-archive'
59
+ when 'zip'
60
+ 'application/zip'
61
+ else
62
+ 'application/octet-stream'
36
63
  end
64
+ @s3_url = URI(upload(make_filename(ext), contents, mime_type: ctype, gzip: false))
65
+ log "uploaded Lambda function to #{@s3_url}"
37
66
  end
38
67
  end
39
68
 
@@ -1,3 +1,3 @@
1
1
  module CloudFormationTool
2
- VERSION = '1.0.9'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudformation-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oded Arbel
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  version: '0'
178
178
  requirements: []
179
179
  rubyforge_project:
180
- rubygems_version: 2.7.7
180
+ rubygems_version: 2.7.8
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: A pre-compiler tool for CloudFormation YAML templates