docker_registry2 1.13.0 → 1.15.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: 7d2c4b1b61074554ed7e15a5d3c662ebeaae19594cb8c4e3e3ba3dc78e67f0c5
4
- data.tar.gz: a1dea179ace034fff0914bbc2a1eb6bcd0dd24cd274f01379a6ffd8215e56c7d
3
+ metadata.gz: 2b93252a450c644a699ad3e18d6350d734de156a6c034d326be58745c8454242
4
+ data.tar.gz: af73611edfe95ec8b47cda4059a82b1902c0c3230dba8399c524e7cb4a6491e0
5
5
  SHA512:
6
- metadata.gz: 7778fc311ce302caf634887a0801490043e7550d819dde8926312b0496134736dfeec474b045ecc5e74a7f29b7195a5977c52b530496edf6a54d187be0ce039e
7
- data.tar.gz: 7ff181d7d3b7fe9ba0f87e2cdf342044a1e4442e55fe760ea5cf351994f41c0bf5d6316b33d1e920533b5ee7032dcb10a4230b5ca5d469dbedbe47919eb4063d
6
+ metadata.gz: 5e2c641cc6a23b0751b535dfebaa780ab87fc9992f7639423537f369e33b8b034b81d2ea215a83117667527c4bdf4998b5df1bae308b70f95f31ccc835082979
7
+ data.tar.gz: a40c907aa5f98b0f1d719d1b3a57a75c9ae39dd95a8fcdc63c596d5444383ea241c6522f1314526ed81bc9c6412f4d1da2f0062dba4704feec24ef509d7fa028
@@ -5,7 +5,7 @@ require 'rest-client'
5
5
  require 'json'
6
6
 
7
7
  module DockerRegistry2
8
- class Registry
8
+ class Registry # rubocop:disable Metrics/ClassLength
9
9
  # @param [#to_s] base_uri Docker registry base URI
10
10
  # @param [Hash] options Client options
11
11
  # @option options [#to_s] :user User name for basic authentication
@@ -17,7 +17,7 @@ module DockerRegistry2
17
17
  # @option options [Hash] :http_options Extra options for RestClient::Request.execute.
18
18
  def initialize(uri, options = {})
19
19
  @uri = URI.parse(uri)
20
- @base_uri = "#{@uri.scheme}://#{@uri.host}:#{@uri.port}"
20
+ @base_uri = "#{@uri.scheme}://#{@uri.host}:#{@uri.port}#{@uri.path}"
21
21
  @user = options[:user]
22
22
  @password = options[:password]
23
23
  @http_options = options[:http_options] || {}
@@ -45,26 +45,22 @@ module DockerRegistry2
45
45
  # response with the URL of the next page. See <https://docs.docker.com/registry/spec/api/#pagination>. This method
46
46
  # iterates over the pages and calls the given block with each response.
47
47
  def paginate_doget(url)
48
- while url
48
+ loop do
49
49
  response = doget(url)
50
50
  yield response
51
51
 
52
- break unless (link = response.headers[:link])
53
-
54
- url = parse_link_header(link)[:next]
52
+ link_header = response.headers[:link]
53
+ break unless link_header
55
54
 
55
+ url = parse_link_header(link_header)[:next]
56
56
  end
57
57
  end
58
58
 
59
59
  def search(query = '')
60
60
  all_repos = []
61
- paginate_doget '/v2/_catalog' do |response|
62
- # parse the response
61
+ paginate_doget('/v2/_catalog') do |response|
63
62
  repos = JSON.parse(response)['repositories']
64
- if query.strip.length.positive?
65
- re = Regexp.new query
66
- repos = repos.find_all { |e| re =~ e }
67
- end
63
+ repos.select! { |repo| repo.match?(/#{query}/) } unless query.empty?
68
64
  all_repos += repos
69
65
  end
70
66
  all_repos
@@ -87,21 +83,9 @@ module DockerRegistry2
87
83
 
88
84
  # do we include the hashes?
89
85
  if withHashes
90
- useGet = false
91
86
  resp['hashes'] = {}
92
87
  resp['tags'].each do |tag|
93
- if useGet
94
- head = doget "/v2/#{repo}/manifests/#{tag}"
95
- else
96
- begin
97
- head = dohead "/v2/#{repo}/manifests/#{tag}"
98
- rescue DockerRegistry2::InvalidMethod
99
- # in case we are in a registry pre-2.3.0, which did not support manifest HEAD
100
- useGet = true
101
- head = doget "/v2/#{repo}/manifests/#{tag}"
102
- end
103
- end
104
- resp['hashes'][tag] = head.headers[:docker_content_digest]
88
+ resp['hashes'][tag] = digest(repo, tag)
105
89
  end
106
90
  end
107
91
 
@@ -142,12 +126,29 @@ module DockerRegistry2
142
126
  end
143
127
  end
144
128
 
145
- def digest(repo, tag)
146
- tag_path = "/v2/#{repo}/manifests/#{tag}"
147
- dohead(tag_path).headers[:docker_content_digest]
148
- rescue DockerRegistry2::InvalidMethod
149
- # Pre-2.3.0 registries didn't support manifest HEAD requests
150
- doget(tag_path).headers[:docker_content_digest]
129
+ def digest(image, tag, architecture = nil, os = nil, variant = nil)
130
+ manifest = manifest(image, tag)
131
+ parsed_manifest = JSON.parse(manifest.body)
132
+
133
+ # Multi-arch images
134
+ if parsed_manifest.key?('manifests')
135
+ manifests = parsed_manifest['manifests']
136
+
137
+ return manifests if architecture.nil? || os.nil?
138
+
139
+ manifests.each do |entry|
140
+ if !variant.nil?
141
+ return entry['digest'] if entry['platform']['architecture'] == architecture && entry['platform']['os'] == os && entry['platform']['variant'] == variant
142
+ elsif entry['platform']['architecture'] == architecture && entry['platform']['os'] == os
143
+ return entry['digest']
144
+ end
145
+ end
146
+
147
+ raise DockerRegistry2::NotFound, "No matches found for the image=#{image} tag=#{tag} os=#{os} architecture=#{architecture}"
148
+
149
+ end
150
+
151
+ parsed_manifest.dig('config', 'digest')
151
152
  end
152
153
 
153
154
  def rmtag(image, tag)
@@ -411,7 +412,14 @@ module DockerRegistry2
411
412
  def headers(payload: nil, bearer_token: nil)
412
413
  headers = {}
413
414
  headers['Authorization'] = "Bearer #{bearer_token}" unless bearer_token.nil?
414
- headers['Accept'] = 'application/vnd.docker.distribution.manifest.v2+json,application/vnd.docker.distribution.manifest.list.v2+json,application/json' if payload.nil?
415
+ if payload.nil?
416
+ headers['Accept'] =
417
+ %w[application/vnd.docker.distribution.manifest.v2+json
418
+ application/vnd.docker.distribution.manifest.list.v2+json
419
+ application/vnd.oci.image.manifest.v1+json
420
+ application/vnd.oci.image.index.v1+json
421
+ application/json].join(',')
422
+ end
415
423
  headers['Content-Type'] = 'application/vnd.docker.distribution.manifest.v2+json' unless payload.nil?
416
424
 
417
425
  headers
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DockerRegistry2
4
- VERSION = '1.13.0'
4
+ VERSION = '1.15.0'
5
5
  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.13.0
4
+ version: 1.15.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: 2022-12-23 00:00:00.000000000 Z
14
+ date: 2023-05-01 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler