hive-messages 1.0.2 → 1.0.3

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
  SHA1:
3
- metadata.gz: 7ce8888c06ae4d9bb6819bc0c15e524bdfa808b3
4
- data.tar.gz: cd28cff00097b2b3490b2053b619d0210f3e970d
3
+ metadata.gz: 010a5f7de0660e6e3c5c42e50534baf87bb11abf
4
+ data.tar.gz: 453093c413e973cadd65e79b4eac155edc23e83c
5
5
  SHA512:
6
- metadata.gz: 9edff75da51b512f71ac0c25dce2440265d93af91a1fca08ec79f30f76f58b7e00fc3b40fea74cf16522718f56745374e785579bb5f95112194f43c5e976655c
7
- data.tar.gz: 3d086b2076f35364f61f7a8d53db0278049d985ebc4ef2640c49ccea752637a1bf8a759cda4b0bb035d9605494130697deb472b9bc2225a6b03a635ea8d0af8e
6
+ metadata.gz: cded9d3a8cebcf5d676b1f823d5cbdd960c4f14cdb70720e1858aad164701694cf47446a629fef2766cd6edadbe80f2e2bc72488f0d5754fc879fd8074e92f70
7
+ data.tar.gz: cb0973943df1eca8b2b42e56d181fbdccb6121c4f124b6423e48220cb6df3e79586e78d50e090a00dacd1c0f8751c55684cab89f181ed5063f52c2fea65e39eb
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "hive-messages"
7
- spec.version = '1.0.2'
7
+ spec.version = '1.0.3'
8
8
  spec.authors = ["David Buckhurst", "Paul Carey"]
9
9
  spec.email = ["david.buckhurst@bbc.co.uk"]
10
10
  spec.summary = %q{Hive communication library.}
@@ -69,24 +69,38 @@ module Hive
69
69
  mime = MimeMagic.by_path(artifact_path)
70
70
  mime_type = mime ? mime.type : 'text/plain'
71
71
 
72
- net_http_args = {:use_ssl => url.instance_of?(URI::HTTPS)}
73
-
74
- if Hive::Messages.configuration.pem_file
75
- pem = File.read(Hive::Messages.configuration.pem_file)
76
- net_http_args[:cert] = OpenSSL::X509::Certificate.new(pem)
77
- net_http_args[:key] = OpenSSL::PKey::RSA.new(pem)
78
- net_http_args[:verify_mode] = Hive::Messages.configuration.ssl_verify_mode
79
- end
72
+ net_http_args = http_args(url)
80
73
 
81
74
  File.open(artifact_path) do |artifact|
82
- req = Net::HTTP::Post::Multipart.new url.path, "data" => UploadIO.new(artifact, mime_type, basename)
83
- res = Net::HTTP.start(url.host, url.port, net_http_args) do |http|
84
- http.request(req)
85
- end
75
+ request = Net::HTTP::Post::Multipart.new url.path, "data" => UploadIO.new(artifact, mime_type, basename)
76
+ res = http_response(url, request, net_http_args)
86
77
  Hive::Messages::Artifact.new.from_json(res.body)
87
78
  end
88
79
  end
89
80
 
81
+ def fetch(uri_str, limit = 10)
82
+ raise ArgumentError, 'too many HTTP redirects' if limit == 0
83
+
84
+ url = URI.parse(uri_str)
85
+ net_http_args = http_args(url)
86
+
87
+ request = Net::HTTP::Get.new(url)
88
+ response = http_response(url, request, net_http_args)
89
+
90
+ case response
91
+ when Net::HTTPSuccess then
92
+ response
93
+ when Net::HTTPRedirection then
94
+ location = response['location']
95
+ warn "redirected to #{location}"
96
+ fetch(location, limit - 1)
97
+ when Net::HTTPNotFound then
98
+ raise "Build not found at location #{uri_str}"
99
+ else
100
+ response.value
101
+ end
102
+ end
103
+
90
104
  def complete
91
105
  self.patch(uri: Hive::Paths::Jobs.complete_url(self.job_id), as: "application/json")
92
106
  end
@@ -95,6 +109,26 @@ module Hive
95
109
  self.message = message
96
110
  self.patch(uri: Hive::Paths::Jobs.error_url(self.job_id), as: "application/json")
97
111
  end
112
+
113
+ private
114
+
115
+ def http_response(url, request, net_http_args)
116
+ Net::HTTP.start(url.host, url.port, net_http_args) do |http|
117
+ http.request(request)
118
+ end
119
+ end
120
+
121
+ def http_args(url)
122
+ net_http_args = {:use_ssl => url.instance_of?(URI::HTTPS)}
123
+ if Hive::Messages.configuration.pem_file
124
+ pem = File.read(Hive::Messages.configuration.pem_file)
125
+ net_http_args[:cert] = OpenSSL::X509::Certificate.new(pem)
126
+ net_http_args[:key] = OpenSSL::PKey::RSA.new(pem)
127
+ net_http_args[:verify_mode] = Hive::Messages.configuration.ssl_verify_mode
128
+ end
129
+ net_http_args
130
+ end
131
+
98
132
  end
99
133
  end
100
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hive-messages
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Buckhurst
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-21 00:00:00.000000000 Z
12
+ date: 2015-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: virtus