artifactory 2.8.0 → 2.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/artifactory/client.rb +31 -13
- data/lib/artifactory/resources/artifact.rb +3 -1
- data/lib/artifactory/version.rb +1 -1
- data/spec/unit/client_spec.rb +17 -0
- data/spec/unit/resources/artifact_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b85783f95f2c304e859d43d9c35399812049fbf
|
4
|
+
data.tar.gz: 5c7d4b82bbdcb8d64effa3ef4d0d205c5ecc1b3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 334b556c77599920368e7aaab3ff2062243872c8f02dc356b4acc4e4e6ec2ebc0db66280c9fb8185e6ed813185b0062c5c94052c46a1b394a805ff83a97dd377
|
7
|
+
data.tar.gz: 6991c793b25068e7d028d0939780809e72186d0dae9dcec1b31ea6107fe76d8015eed1d937030af34322a3dfa803144bb5239dc5404f7bf8da4b737f6238e146
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@ Artifactory Client CHANGELOG
|
|
3
3
|
This file is used to document the changes between releases of the Artifactory
|
4
4
|
Ruby client.
|
5
5
|
|
6
|
+
v2.8.1 (03-21-2017)
|
7
|
+
-------------------
|
8
|
+
- Allow downloading of large files. Fixes #83.
|
9
|
+
|
6
10
|
v2.8.0 (03-17-2017)
|
7
11
|
-------------------
|
8
12
|
- Include statuses in Build resource
|
data/lib/artifactory/client.rb
CHANGED
@@ -90,16 +90,21 @@ module Artifactory
|
|
90
90
|
#
|
91
91
|
# Make a HTTP GET request
|
92
92
|
#
|
93
|
+
# If a block is provided the response body is yielded in chunks/fragments
|
94
|
+
# as it is read from the undelrying socket.
|
95
|
+
#
|
93
96
|
# @param path (see Client#request)
|
94
97
|
# @param [Hash] params
|
95
98
|
# the list of query params
|
96
99
|
# @param headers (see Client#request)
|
97
100
|
#
|
101
|
+
# @yield [chunk] Partial piece of response body
|
102
|
+
#
|
98
103
|
# @raise (see Client#request)
|
99
104
|
# @return (see Client#request)
|
100
105
|
#
|
101
|
-
def get(path, params = {}, headers = {})
|
102
|
-
request(:get, path, params, headers)
|
106
|
+
def get(path, params = {}, headers = {}, &block)
|
107
|
+
request(:get, path, params, headers, &block)
|
103
108
|
end
|
104
109
|
|
105
110
|
#
|
@@ -162,7 +167,9 @@ module Artifactory
|
|
162
167
|
#
|
163
168
|
# Make an HTTP request with the given verb, data, params, and headers. If
|
164
169
|
# the response has a return type of JSON, the JSON is automatically parsed
|
165
|
-
# and returned as a hash; otherwise it is returned as a string.
|
170
|
+
# and returned as a hash; otherwise it is returned as a string. If a block
|
171
|
+
# is provided the response body is yielded in chunks/fragments as it is
|
172
|
+
# read from the undelrying socket.
|
166
173
|
#
|
167
174
|
# @raise [Error::HTTPError]
|
168
175
|
# if the request is not an HTTP 200 OK
|
@@ -177,10 +184,12 @@ module Artifactory
|
|
177
184
|
# @param [Hash] headers
|
178
185
|
# the list of headers to use
|
179
186
|
#
|
187
|
+
# @yield [chunk] Partial piece of response body
|
188
|
+
#
|
180
189
|
# @return [String, Hash]
|
181
190
|
# the response body
|
182
191
|
#
|
183
|
-
def request(verb, path, data = {}, headers = {})
|
192
|
+
def request(verb, path, data = {}, headers = {}, &block)
|
184
193
|
# Build the URI and request object from the given information
|
185
194
|
uri = build_uri(verb, path, data)
|
186
195
|
request = class_for_request(verb).new(uri.request_uri)
|
@@ -245,16 +254,25 @@ module Artifactory
|
|
245
254
|
# Create a connection using the block form, which will ensure the socket
|
246
255
|
# is properly closed in the event of an error.
|
247
256
|
connection.start do |http|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
success(response)
|
257
|
+
|
258
|
+
if block_given?
|
259
|
+
http.request(request) do |response|
|
260
|
+
response.read_body do |chunk|
|
261
|
+
yield chunk
|
262
|
+
end
|
263
|
+
end
|
256
264
|
else
|
257
|
-
|
265
|
+
response = http.request(request)
|
266
|
+
|
267
|
+
case response
|
268
|
+
when Net::HTTPRedirection
|
269
|
+
redirect = URI.parse(response["location"])
|
270
|
+
request(verb, redirect, data, headers)
|
271
|
+
when Net::HTTPSuccess
|
272
|
+
success(response)
|
273
|
+
else
|
274
|
+
error(response)
|
275
|
+
end
|
258
276
|
end
|
259
277
|
end
|
260
278
|
rescue SocketError, Errno::ECONNREFUSED, EOFError
|
@@ -502,7 +502,9 @@ module Artifactory
|
|
502
502
|
destination = File.join(target, filename)
|
503
503
|
|
504
504
|
File.open(destination, "wb") do |file|
|
505
|
-
|
505
|
+
client.get(download_uri) do |chunk|
|
506
|
+
file.write chunk
|
507
|
+
end
|
506
508
|
end
|
507
509
|
|
508
510
|
destination
|
data/lib/artifactory/version.rb
CHANGED
data/spec/unit/client_spec.rb
CHANGED
@@ -46,6 +46,13 @@ module Artifactory
|
|
46
46
|
expect(subject).to receive(:request).with(:get, "/foo", {}, {})
|
47
47
|
subject.get("/foo")
|
48
48
|
end
|
49
|
+
|
50
|
+
context "called with a block" do
|
51
|
+
it "yields the response in chunks" do
|
52
|
+
expect(subject).to receive(:request).with(:get, "/foo", {}, {}) { |&block| block.call("Chunked Body") }
|
53
|
+
expect { |chunk| subject.get("/foo", &chunk) }.to yield_with_args("Chunked Body")
|
54
|
+
end
|
55
|
+
end
|
49
56
|
end
|
50
57
|
|
51
58
|
describe "#post" do
|
@@ -90,6 +97,16 @@ module Artifactory
|
|
90
97
|
expect { subject.request(:get, "/") }.to raise_error(Error::HTTPError)
|
91
98
|
end
|
92
99
|
end
|
100
|
+
|
101
|
+
context "called with a block" do
|
102
|
+
before { stub_request(:get, /.+/).to_return(status: 200, body: "Chunked Body") }
|
103
|
+
|
104
|
+
it "yields the response in chunks" do
|
105
|
+
subject.request(:get, "/foo") do |chunk|
|
106
|
+
expect(chunk).to eq("Chunked Body")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
93
110
|
end
|
94
111
|
|
95
112
|
describe "#to_query_string" do
|
@@ -560,6 +560,20 @@ module Artifactory
|
|
560
560
|
expect(Dir.entries(tmpdir)).to include("foobar.deb")
|
561
561
|
end
|
562
562
|
end
|
563
|
+
|
564
|
+
it "writes the file in chunks" do
|
565
|
+
Dir.mktmpdir("artifact_download") do |tmpdir|
|
566
|
+
subject.download_uri = "/artifact.deb"
|
567
|
+
|
568
|
+
expect(client).to receive(:get).and_yield("some content")
|
569
|
+
|
570
|
+
file = double("file")
|
571
|
+
expect(File).to receive(:open).with(File.join(tmpdir, "artifact.deb"), "wb").and_yield(file)
|
572
|
+
expect(file).to receive(:write).with("some content")
|
573
|
+
|
574
|
+
subject.download(tmpdir)
|
575
|
+
end
|
576
|
+
end
|
563
577
|
end
|
564
578
|
|
565
579
|
describe "#relative_path" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artifactory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.8.
|
4
|
+
version: 2.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Vargo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|