cloudspin-stack 0.1.25 → 0.1.26

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: 4f264c24f8c189e2911364446d2e52424b858f7f652894accc71d9793cb3786c
4
- data.tar.gz: 6e18307aaf5df5233599443d14eccc1f7a05d1f91735a95b6ba2494cc2bc741a
3
+ metadata.gz: 3b334f2e638d35e7d95cf7442d61e945b75397daa27aeed2c146af701c9ba412
4
+ data.tar.gz: 036ed173c2ab38c115e0df2646851cd01036b2e397b96c462a86ff5b8a171c18
5
5
  SHA512:
6
- metadata.gz: 61bb3efbd60147ca0017cb37a514d3e5c4669ec2b5790c48c9b9448a96d749ccb002ada8adef9cf6156867cd5b451e75174fefcd52f4eca93dd2d91c8455449e
7
- data.tar.gz: f5c0104a653960c391a8580134a9d22f2cc98de89b27e16c67a886258fa1e01c598120837cb5c157461973fce7cbf228f34d83abc65273865a915e4d57e42a1f
6
+ metadata.gz: 60c63aaecf8c0dfd82fcdb610ae55bd813d064e59389378e3ed4fb5acaefa92c23db9c05816d3960b60f67824472a92a10023537833d76dc76c732bf0e5fb9cd
7
+ data.tar.gz: 125c065e33ab6231bed9bf4192519e95707dc21e483ba343aefe2969bbc3cfa2daabd5f9e7376379dfb198c6977c86f95844df639c7ce9954ef9d99d6481f1a3
@@ -23,24 +23,44 @@ module Cloudspin
23
23
  download_file(artefact_url, zipfile)
24
24
  end
25
25
 
26
- def download_file(remote_file, local_file)
26
+ def download_file(remote_file, local_file, tries = 0)
27
+ raise "Too many redirects (#{remote_file})" if tries > 9
27
28
  remote_file_uri = URI(remote_file)
28
- Net::HTTP.start(remote_file_uri.host, remote_file_uri.port) do |remote|
29
- response = remote.get(remote_file_uri)
30
- open(local_file, 'wb') do |local|
31
- local.write(response.body)
29
+
30
+ Net::HTTP.start(
31
+ remote_file_uri.host,
32
+ remote_file_uri.port,
33
+ :use_ssl => remote_file_uri.scheme == 'https'
34
+ ) do |http|
35
+ request = Net::HTTP::Get.new(remote_file_uri)
36
+ http.request(request) do |response|
37
+ case response
38
+ when Net::HTTPSuccess then write_local_file(response, local_file)
39
+ when Net::HTTPRedirection then download_file(response['Location'], local_file, tries + 1)
40
+ else
41
+ raise "Request to '#{remote_file_uri}' failed: #{response.error} #{response.inspect}"
42
+ end
32
43
  end
33
44
  end
45
+
46
+ # puts "DEBUG: Downloaded file to #{local_file}"
34
47
  local_file
35
48
  end
36
49
 
50
+ def write_local_file(response, local_file)
51
+ open(local_file, 'wb') do |io|
52
+ response.read_body do |chunk|
53
+ io.write chunk
54
+ end
55
+ end
56
+ end
57
+
37
58
  def unpack(zipfile, where_to_put_it)
38
59
  folder_name = path_of_source_in(zipfile)
39
60
  # puts "DEBUG: Unzipping #{zipfile} to #{where_to_put_it}"
40
61
  clear_folder(where_to_put_it)
41
62
  Zip::File.open(zipfile) { |zip_file|
42
63
  zip_file.each { |f|
43
- # puts "-> #{f.name}"
44
64
  f_path = File.join(where_to_put_it, f.name)
45
65
  FileUtils.mkdir_p(File.dirname(f_path))
46
66
  # puts "DEBUG: Extracting #{f} to #{f_path}"
@@ -61,13 +81,15 @@ module Cloudspin
61
81
 
62
82
  def path_of_configuration_file_in(zipfile_path)
63
83
  zipfile = Zip::File.open(zipfile_path)
64
- begin
84
+ list_of_files = begin
65
85
  zipfile.entries.select { |entry|
66
- /^stack-definition.yaml$/.match entry.name
67
- }.first.name
86
+ /^stack-definition.yaml$/.match entry.name or /[\.\/]stack-definition.yaml$/.match entry.name
87
+ }
68
88
  ensure
69
89
  zipfile.close
70
90
  end
91
+ raise MissingStackDefinitionConfigurationFileError, "No configuration file in #{zipfile_path}" if list_of_files.empty?
92
+ list_of_files.first.name
71
93
  end
72
94
 
73
95
  end
@@ -1,5 +1,5 @@
1
1
  module Cloudspin
2
2
  module Stack
3
- VERSION = '0.1.25'
3
+ VERSION = '0.1.26'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudspin-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.25
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'kief '
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-07 00:00:00.000000000 Z
11
+ date: 2018-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-terraform