docker_registry2 1.9.0 → 1.11.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: b4b040151a73ef44e9ac9b07bb2998283fb86e1ed33d41cc523b6229e1372121
4
- data.tar.gz: 0b27fcb25ccbe51eb4ee88655ba076d93daa8ed26de37ff0ef32185edceb9b54
3
+ metadata.gz: 7c94a748970c4e621a4bb1b856ea14915fbc83b55cff85743e7ef4333afb2360
4
+ data.tar.gz: 340ce8d170519eb1a958a3c4d08314658d214ad0bd3e8c57d30d931086d885b0
5
5
  SHA512:
6
- metadata.gz: 0f04c98177280e070b1d2fdc0b9577027a8802db7aa91eac54d62b5adf0043b242d6e3d896a83f8805717c5c551e16585d0c64183247149c62196e7d3092d1b6
7
- data.tar.gz: a4101e6d617104332dbf23a0a2edd4b61dbad4b7f7844317fddbad81461a07671c405195380db95173823217e37b0c7aa839b2fa74b621cf26387a3366e06357
6
+ metadata.gz: d4b64a53ae13758dadce8fd95708fbabd76cc604a740194584ba472022a2fd71c01c7526c1d577fa7aa253a8c72df069dce5b8242e48402dc2518f1d9e117633
7
+ data.tar.gz: e3416ec4b0d38da96d5f7053b791f5d1b795b00a10a91d30c7aef30d454956728b94751cbb3d3eeeb9ac2a980404c1a5abbfdb0f327044e500891db20bc9c169
data/README.md CHANGED
@@ -55,6 +55,13 @@ opts = { open_timeout: 2, read_timeout: 5 }
55
55
  reg = DockerRegistry2.connect("https://my.registy.corp.com", opts)
56
56
  ```
57
57
 
58
+ Your may pass extra options for RestClient::Request.execute through `http_options` :
59
+
60
+ ```ruby
61
+ opts = { http_options: { proxy: 'http://proxy.example.com:8080/' } }
62
+ reg = DockerRegistry2.connect("https://my.registy.corp.com", opts)
63
+ ```
64
+
58
65
  You can connect anonymously or with credentials:
59
66
 
60
67
  #### Anonymous
@@ -8,8 +8,6 @@ require File.dirname(__FILE__) + '/registry/blob'
8
8
  module DockerRegistry2
9
9
  def self.connect(uri="https://registry.hub.docker.com",opts={})
10
10
  @reg = DockerRegistry2::Registry.new(uri,opts)
11
- @reg.ping
12
- @reg
13
11
  end
14
12
 
15
13
  def self.search(query = '')
@@ -7,15 +7,19 @@ class DockerRegistry2::Registry
7
7
  # @param [Hash] options Client options
8
8
  # @option options [#to_s] :user User name for basic authentication
9
9
  # @option options [#to_s] :password Password for basic authentication
10
- # @option options [#to_s] :open_timeout Time to wait for a connection with a registry
11
- # @option options [#to_s] :read_timeout Time to wait for data from a registry
10
+ # @option options [#to_s] :open_timeout Time to wait for a connection with a registry.
11
+ # It is ignored if http_options[:open_timeout] is also specified.
12
+ # @option options [#to_s] :read_timeout Time to wait for data from a registry.
13
+ # It is ignored if http_options[:read_timeout] is also specified.
14
+ # @option options [Hash] :http_options Extra options for RestClient::Request.execute.
12
15
  def initialize(uri, options = {})
13
16
  @uri = URI.parse(uri)
14
17
  @base_uri = "#{@uri.scheme}://#{@uri.host}:#{@uri.port}"
15
18
  @user = options[:user]
16
19
  @password = options[:password]
17
- @open_timeout = options[:open_timeout] || 2
18
- @read_timeout = options[:read_timeout] || 5
20
+ @http_options = options[:http_options] || {}
21
+ @http_options[:open_timeout] ||= options[:open_timeout] || 2
22
+ @http_options[:read_timeout] ||= options[:read_timeout] || 5
19
23
  end
20
24
 
21
25
  def doget(url)
@@ -34,10 +38,6 @@ class DockerRegistry2::Registry
34
38
  return doreq "head", url
35
39
  end
36
40
 
37
- def ping
38
- response = doget '/v2/'
39
- end
40
-
41
41
  def search(query = '')
42
42
  response = doget "/v2/_catalog"
43
43
  # parse the response
@@ -109,13 +109,13 @@ class DockerRegistry2::Registry
109
109
 
110
110
  def blob(repo, digest, outpath=nil)
111
111
  blob_url = "/v2/#{repo}/blobs/#{digest}"
112
- if outpath.nil?
112
+ if outpath.nil?
113
113
  response = doget(blob_url)
114
114
  DockerRegistry2::Blob.new(response.headers, response.body)
115
115
  else
116
116
  File.open(outpath, 'w') do |fd|
117
117
  doreq('get', blob_url, fd)
118
- end
118
+ end
119
119
 
120
120
  outpath
121
121
  end
@@ -217,13 +217,15 @@ class DockerRegistry2::Registry
217
217
  parts.each do |part, index|
218
218
  section = part.split(';')
219
219
  url = section[0][/<(.*)>/,1]
220
- name = section[1][/rel="(.*)"/,1].to_sym
220
+ name = section[1][/rel="?([^"]*)"?/,1].to_sym
221
221
  links[name] = url
222
222
  end
223
223
 
224
224
  if links[:next]
225
225
  query=URI(links[:next]).query
226
- last=URI::decode_www_form(query).to_h["last"]
226
+ link_key = @uri.host.eql?('quay.io') ? 'next_page' : 'last'
227
+ last=URI::decode_www_form(query).to_h[link_key]
228
+
227
229
  end
228
230
  last
229
231
  end
@@ -244,22 +246,20 @@ class DockerRegistry2::Registry
244
246
  stream.write chunk
245
247
  end
246
248
  }
247
- response = RestClient::Request.execute(
249
+ response = RestClient::Request.execute(@http_options.merge(
248
250
  method: type,
249
251
  url: @base_uri+url,
250
252
  headers: headers(payload: payload),
251
253
  block_response: block,
252
- open_timeout: @open_timeout,
253
- read_timeout: @read_timeout,
254
254
  payload: payload
255
- )
255
+ ))
256
256
  rescue SocketError
257
257
  raise DockerRegistry2::RegistryUnknownException
258
258
  rescue RestClient::NotFound => error
259
259
  raise DockerRegistry2::NotFound, error
260
260
  rescue RestClient::Unauthorized => e
261
261
  header = e.response.headers[:www_authenticate]
262
- method = header.downcase.split(' ')[0]
262
+ method = header.to_s.downcase.split(' ')[0]
263
263
  case method
264
264
  when 'basic'
265
265
  response = do_basic_req(type, url, stream, payload)
@@ -279,17 +279,15 @@ class DockerRegistry2::Registry
279
279
  stream.write chunk
280
280
  end
281
281
  }
282
- response = RestClient::Request.execute(
282
+ response = RestClient::Request.execute(@http_options.merge(
283
283
  method: type,
284
284
  url: @base_uri+url,
285
285
  user: @user,
286
286
  password: @password,
287
287
  headers: headers(payload: payload),
288
288
  block_response: block,
289
- open_timeout: @open_timeout,
290
- read_timeout: @read_timeout,
291
289
  payload: payload
292
- )
290
+ ))
293
291
  rescue SocketError
294
292
  raise DockerRegistry2::RegistryUnknownException
295
293
  rescue RestClient::Unauthorized
@@ -310,15 +308,13 @@ class DockerRegistry2::Registry
310
308
  stream.write chunk
311
309
  end
312
310
  }
313
- response = RestClient::Request.execute(
311
+ response = RestClient::Request.execute(@http_options.merge(
314
312
  method: type,
315
313
  url: @base_uri+url,
316
314
  headers: headers(payload: payload, bearer_token: token),
317
315
  block_response: block,
318
- open_timeout: @open_timeout,
319
- read_timeout: @read_timeout,
320
316
  payload: payload
321
- )
317
+ ))
322
318
  rescue SocketError
323
319
  raise DockerRegistry2::RegistryUnknownException
324
320
  rescue RestClient::Unauthorized
@@ -342,14 +338,12 @@ class DockerRegistry2::Registry
342
338
  # authenticate against the realm
343
339
  uri = URI.parse(target[:realm])
344
340
  begin
345
- response = RestClient::Request.execute(
341
+ response = RestClient::Request.execute(@http_options.merge(
346
342
  method: :get,
347
343
  url: uri.to_s, headers: {params: target[:params]},
348
344
  user: @user,
349
345
  password: @password,
350
- open_timeout: @open_timeout,
351
- read_timeout: @read_timeout
352
- )
346
+ ))
353
347
  rescue RestClient::Unauthorized, RestClient::Forbidden
354
348
  # bad authentication
355
349
  raise DockerRegistry2::RegistryAuthenticationException
@@ -1,3 +1,3 @@
1
1
  module DockerRegistry2
2
- VERSION = '1.9.0'
2
+ VERSION = '1.11.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_registry2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avi Deitcher https://github.com/deitch
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-12-01 00:00:00.000000000 Z
14
+ date: 2022-07-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.0.3
105
+ rubygems_version: 3.1.6
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Docker v2 registry HTTP API client