cloudformation-tool 1.0.1 → 1.0.2

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: ef4e953cd8194f197b68c1e110dae6f3a81f5c4e2730fe63950d5ac1392f1b02
4
- data.tar.gz: 9d5ea95468d689707ec79534281ea14ae51521d3491787e523a1ef0c11c295a8
3
+ metadata.gz: 83b8efc5704070ab9a788b2a90abd76c5cddf51e001a809b8eb4232404d6a4a1
4
+ data.tar.gz: 09e63883d8159f6331d06f8b5b4af28888f755134f55972272b53df0bd7fe3e6
5
5
  SHA512:
6
- metadata.gz: d43ffe6a9b74696f7a96c36a4f25bcc51322bd61f6d72000133ba6ef13720bd9412132c693597d40018b9bfd771038e576a1739e3c0b2e1cf895ecbdfaaaeee1
7
- data.tar.gz: 1b6226952862d335bfa9970b8c394e9201548284af96363a39c54c00aac1a6ba946207c2076676c983fbe17c07fef566c23047aec842cc4dd71db6a3f4b7c31d
6
+ metadata.gz: bbf45c2d3e1e03db1ae3e686e5432175547e00dc92db30ed12bf4bf03c66c2d8be8832cb1e1244a67025379a3918162962a071c67431468ea83795669c7eac58
7
+ data.tar.gz: 4e6480feac36232936ef892541aa0cd6e528547dab38721b0acb290db1360ee1ebd8f9cadd45f6c02cac43f3701d0298fc45c744175a1dde8ab2ae42bf1ab349
@@ -15,7 +15,9 @@ module CloudFormationTool
15
15
  @data['Url'] = url = tpl.resolveVal(@data['Url'])
16
16
  return unless url.is_a? String
17
17
  log "Downloading Lambda code from #{url}"
18
- unless already_in_cache(url)
18
+ if already_in_cache(url)
19
+ log "Reusing remote cached object instead of downloading"
20
+ else
19
21
  res = fetch_from_url(url)
20
22
  @s3_url = URI(upload(make_filename(url.split('.').last), res.body, mime_type: res['content-type'], gzip: false))
21
23
  log "uploaded Lambda function to #{@s3_url}"
@@ -51,27 +53,35 @@ module CloudFormationTool
51
53
  end
52
54
  end
53
55
 
54
- def already_in_cache(uri_str, limit = 10)
55
- raise ArgumentError, 'too many HTTP redirects' if limit == 0
56
+ def already_in_cache(uri_str)
57
+ limit = 10
56
58
  url = URI(uri_str)
57
- begin
58
- Net::HTTP.start(url.host, url.port) do |http|
59
- request = Net::HTTP::Get.new(url)
60
- http.request(request) do |response|
61
- # handle redirects like Github likes to do
62
- case response
63
- when Net::HTTPSuccess then
64
- check_cached(response['ETag'])
65
- when Net::HTTPRedirection then
66
- location = response['location']
67
- log "redirected to #{location}"
68
- already_in_cache(location, limit - 1)
69
- else
70
- raise ArgumentError, "Error getting response: #{response}"
59
+ until url.nil?
60
+ begin
61
+ raise ArgumentError, 'too many HTTP redirects' if limit == 0
62
+ Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
63
+ request = Net::HTTP::Get.new(url)
64
+ http.request(request) do |response|
65
+ # handle redirects like Github likes to do
66
+ case response
67
+ when Net::HTTPSuccess then
68
+ url = nil
69
+ http.finish if check_cached(response['ETag'])
70
+ when Net::HTTPRedirection then
71
+ location = response['location']
72
+ log "Cache check redirected to #{location}"
73
+ limit = limit - 1
74
+ response.body
75
+ url = URI(location)
76
+ else
77
+ log "arg err"
78
+ raise ArgumentError, "Error getting response: #{response}"
79
+ end
71
80
  end
72
81
  end
82
+ rescue IOError => e
83
+ retry unless url.nil?
73
84
  end
74
- rescue EOFError
75
85
  end
76
86
  !@s3_url.nil?
77
87
  end
@@ -79,9 +89,11 @@ module CloudFormationTool
79
89
  def check_cached(etag)
80
90
  etag.gsub!(/"/,'') unless etag.nil?
81
91
  o = cached_object(etag)
82
- unless o.nil?
83
- log 'reusing cached object'
84
- @s3_url = o.public_url
92
+ if o.nil?
93
+ false
94
+ else
95
+ @s3_url = URI(o.public_url)
96
+ true
85
97
  end
86
98
  end
87
99
 
@@ -1,3 +1,3 @@
1
1
  module CloudFormationTool
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
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.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oded Arbel