docker_registry2 1.10.0 → 1.12.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: 6878db7e5b30918ddcb5417f6092ae01a35ca6037c9d0203217450198fe831d0
4
- data.tar.gz: 207bc12bacd847a6573b322cdee58c3fe33bb85db1c831458cca7e942f8232bd
3
+ metadata.gz: 869a69624555c180f16132300dfc203787a4e3ffd616f49f26ec7f199b469f1a
4
+ data.tar.gz: cab7c1746af1ef6956726f42524da542f2ebf9a2fe4a56cc793148aa04a285d4
5
5
  SHA512:
6
- metadata.gz: fe5ef7fec4e79b5290bafce6837738410e41c0dd50bdeab49ce373bc256338ca0c6300d28417e13cf686d813e71b1ff44315afb80196f19dd84f7b4b870e7008
7
- data.tar.gz: aad38ab842512d57ed2816f3823d2fb77ab8cbf56ef48c29df476d630881dadaf8de0c71fd543a5c0d5ddf4625baadc38f4a2b860f39d712650d2ba574153d81
6
+ metadata.gz: 953669f5e94fef460fe7a3d866964aa76c87a29b2e2285ecb9a85a7058c43317ea1a683aa96e4c23bda450f48805edbc5c681f601ce00a81ae1e93020f6e02c0
7
+ data.tar.gz: 02fbf888184e024bdf49a62b8b2e4161ae02d1df7f265bbf93aa5e4244fde50221e4fd93e085c291f4333c2ba691ffcc469d016832091c8cb3a286bea39978ba
@@ -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 = '')
@@ -38,19 +38,34 @@ class DockerRegistry2::Registry
38
38
  return doreq "head", url
39
39
  end
40
40
 
41
- def ping
42
- doget '/v2/'
41
+ # When a result set is too large, the Docker registry returns only the first items and adds a Link header in the
42
+ # response with the URL of the next page. See <https://docs.docker.com/registry/spec/api/#pagination>. This method
43
+ # iterates over the pages and calls the given block with each response.
44
+ def paginate_doget(url)
45
+ while url
46
+ response = doget(url)
47
+ yield response
48
+
49
+ if (link = response.headers[:link])
50
+ url = parse_link_header(link)[:next]
51
+ else
52
+ break
53
+ end
54
+ end
43
55
  end
44
56
 
45
57
  def search(query = '')
46
- response = doget "/v2/_catalog"
47
- # parse the response
48
- repos = JSON.parse(response)["repositories"]
49
- if query.strip.length > 0
50
- re = Regexp.new query
51
- repos = repos.find_all {|e| re =~ e }
58
+ all_repos = []
59
+ paginate_doget "/v2/_catalog" do |response|
60
+ # parse the response
61
+ repos = JSON.parse(response)["repositories"]
62
+ if query.strip.length > 0
63
+ re = Regexp.new query
64
+ repos = repos.find_all {|e| re =~ e }
65
+ end
66
+ all_repos += repos
52
67
  end
53
- return repos
68
+ all_repos
54
69
  end
55
70
 
56
71
  def tags(repo,count=nil,last="",withHashes = false, auto_paginate: false)
@@ -113,13 +128,13 @@ class DockerRegistry2::Registry
113
128
 
114
129
  def blob(repo, digest, outpath=nil)
115
130
  blob_url = "/v2/#{repo}/blobs/#{digest}"
116
- if outpath.nil?
131
+ if outpath.nil?
117
132
  response = doget(blob_url)
118
133
  DockerRegistry2::Blob.new(response.headers, response.body)
119
134
  else
120
135
  File.open(outpath, 'w') do |fd|
121
136
  doreq('get', blob_url, fd)
122
- end
137
+ end
123
138
 
124
139
  outpath
125
140
  end
@@ -212,7 +227,9 @@ class DockerRegistry2::Registry
212
227
  Integer(response.headers[:content_length],10)
213
228
  end
214
229
 
215
- def last(header)
230
+ # Parse the value of the Link HTTP header and return a Hash whose keys are the rel values turned into symbols, and
231
+ # the values are URLs. For example, `{ next: '/v2/_catalog?n=100&last=x' }`.
232
+ def parse_link_header(header)
216
233
  last=''
217
234
  parts = header.split(',')
218
235
  links = Hash.new
@@ -221,13 +238,20 @@ class DockerRegistry2::Registry
221
238
  parts.each do |part, index|
222
239
  section = part.split(';')
223
240
  url = section[0][/<(.*)>/,1]
224
- name = section[1][/rel="(.*)"/,1].to_sym
241
+ name = section[1][/rel="?([^"]*)"?/,1].to_sym
225
242
  links[name] = url
226
243
  end
227
244
 
245
+ links
246
+ end
247
+
248
+ def last(header)
249
+ links = parse_link_header(header)
228
250
  if links[:next]
229
251
  query=URI(links[:next]).query
230
- last=URI::decode_www_form(query).to_h["last"]
252
+ link_key = @uri.host.eql?('quay.io') ? 'next_page' : 'last'
253
+ last=URI::decode_www_form(query).to_h[link_key]
254
+
231
255
  end
232
256
  last
233
257
  end
@@ -261,7 +285,7 @@ class DockerRegistry2::Registry
261
285
  raise DockerRegistry2::NotFound, error
262
286
  rescue RestClient::Unauthorized => e
263
287
  header = e.response.headers[:www_authenticate]
264
- method = header.downcase.split(' ')[0]
288
+ method = header.to_s.downcase.split(' ')[0]
265
289
  case method
266
290
  when 'basic'
267
291
  response = do_basic_req(type, url, stream, payload)
@@ -1,3 +1,3 @@
1
1
  module DockerRegistry2
2
- VERSION = '1.10.0'
2
+ VERSION = '1.12.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.10.0
4
+ version: 1.12.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: 2020-11-29 00:00:00.000000000 Z
14
+ date: 2022-08-23 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.1.4
105
+ rubygems_version: 3.1.6
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Docker v2 registry HTTP API client