docker-remote 0.2.0 → 0.3.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: 19acf54d628fdf18296c7a86ffdd6760840f7222fa28e5438e5b0edc7bac7136
4
- data.tar.gz: 1ce08796037731c708c9f5ce79e8038d31d288654f0ea7070166a2d6ac4e711c
3
+ metadata.gz: fbe61af8e8709e3a11eb1df8bc561477d38c3540ce2d216bc81dc999d31822cf
4
+ data.tar.gz: 65a9d5336374a275246dc6ba950c3a4288823286ae1884f43f5a5bb748348c50
5
5
  SHA512:
6
- metadata.gz: 273f430350900735e9efb3a63155d01d32d14afcc7ab5b34b94250e2de0d12c2cd5301f88d08c0729513848f06a559b918d7a762a0b1803854c6f8069e9263f3
7
- data.tar.gz: 60684d86a0675c3465455b3df6373144db0894a908fd5c0491c5b822a7c5544d00dd50121a3d57d666ea4b5a4b0a4a34b674c29bd6e25e690c142217a63c60d0
6
+ metadata.gz: 6d04a849e0fe6fda791f19be79f7664a95f3c24c7b6a38c7b2f0831a9af09690c825c54b3a62c8477da65ac06902bb9bce712427c62dfbe8b619d4a9d24ad098
7
+ data.tar.gz: e927985c4d0a6b767941ce5ac77647c8e1c5e6c45446221fd3f237cfbf4f29754a54cf9eb08db6597aa694fb3f2eb8611d9660280771a8819fe82446c93568b5
@@ -1,3 +1,7 @@
1
+ ## 0.3.0
2
+ * Support registries with no auth.
3
+ * Raise errors upon receiving unexpected response codes during auth flow.
4
+
1
5
  ## 0.2.0
2
6
  * Support both basic and bearer auth.
3
7
 
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gemspec
4
4
 
5
5
  group :development do
6
6
  gem 'rake'
7
+ gem 'pry-byebug'
7
8
  end
8
9
 
9
10
  group :test do
@@ -10,6 +10,7 @@ module Docker
10
10
  autoload :BasicAuth, 'docker/remote/basic_auth'
11
11
  autoload :BearerAuth, 'docker/remote/bearer_auth'
12
12
  autoload :Client, 'docker/remote/client'
13
+ autoload :NoAuth, 'docker/remote/no_auth'
13
14
  autoload :Utils, 'docker/remote/utils'
14
15
  end
15
16
  end
@@ -4,6 +4,10 @@ require 'uri'
4
4
 
5
5
  module Docker
6
6
  module Remote
7
+ class DockerRemoteError < StandardError; end
8
+ class UnsupportedVersionError < DockerRemoteError; end
9
+ class UnexpectedResponseCodeError < DockerRemoteError; end
10
+
7
11
  class Client
8
12
  include Utils
9
13
 
@@ -43,35 +47,55 @@ module Docker
43
47
  @auth ||= begin
44
48
  request = Net::HTTP::Get.new('/v2/')
45
49
  response = registry_http.request(request)
46
- auth = response['www-authenticate']
47
-
48
- idx = auth.index(' ')
49
- auth_type = auth[0..idx].strip
50
-
51
- params = auth[idx..-1].split(',').each_with_object({}) do |param, ret|
52
- key, value = param.split('=')
53
- ret[key.strip] = value.strip[1..-2] # remove quotes
54
- end
55
50
 
56
- case auth_type.downcase
57
- when 'bearer'
58
- BearerAuth.new(params, repo, username, password)
59
- when 'basic'
60
- BasicAuth.new(username, password)
51
+ case response.code
52
+ when '200'
53
+ NoAuth.instance
54
+ when '401'
55
+ www_auth(response)
56
+ when '404'
57
+ raise UnsupportedVersionError,
58
+ "the registry at #{registry_url} doesn't support v2 "\
59
+ 'of the Docker registry API'
61
60
  else
62
- raise UnsupportedAuthTypeError, "unsupported Docker auth type '#{auth_type}'"
61
+ raise UnexpectedResponseCodeError,
62
+ "the registry at #{registry_url} responded with an "\
63
+ "unexpected HTTP status code of #{response.code}"
63
64
  end
64
65
  end
65
66
  end
66
67
 
68
+ def www_auth(response)
69
+ auth = response['www-authenticate']
70
+
71
+ idx = auth.index(' ')
72
+ auth_type = auth[0..idx].strip
73
+
74
+ params = auth[idx..-1].split(',').each_with_object({}) do |param, ret|
75
+ key, value = param.split('=')
76
+ ret[key.strip] = value.strip[1..-2] # remove quotes
77
+ end
78
+
79
+ case auth_type.downcase
80
+ when 'bearer'
81
+ BearerAuth.new(params, repo, username, password)
82
+ when 'basic'
83
+ BasicAuth.new(username, password)
84
+ else
85
+ raise UnsupportedAuthTypeError,
86
+ "unsupported Docker auth type '#{auth_type}'"
87
+ end
88
+ end
89
+
67
90
  def registry_uri
68
91
  @registry_uri ||= URI.parse(registry_url)
69
92
  end
70
93
 
71
94
  def registry_http
72
- @registry_http ||= Net::HTTP.new(registry_uri.host, registry_uri.port).tap do |http|
73
- http.use_ssl = true if registry_uri.scheme == 'https'
74
- end
95
+ @registry_http ||=
96
+ Net::HTTP.new(registry_uri.host, registry_uri.port).tap do |http|
97
+ http.use_ssl = true if registry_uri.scheme == 'https'
98
+ end
75
99
  end
76
100
  end
77
101
  end
@@ -0,0 +1,11 @@
1
+ module Docker
2
+ module Remote
3
+ class NoAuth
4
+ include Singleton
5
+
6
+ def make_get(path)
7
+ Net::HTTP::Get.new(path)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Docker
2
2
  module Remote
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-26 00:00:00.000000000 Z
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby client for communicating with the Docker registry API v2.
14
14
  email:
@@ -26,6 +26,7 @@ files:
26
26
  - lib/docker/remote/basic_auth.rb
27
27
  - lib/docker/remote/bearer_auth.rb
28
28
  - lib/docker/remote/client.rb
29
+ - lib/docker/remote/no_auth.rb
29
30
  - lib/docker/remote/utils.rb
30
31
  - lib/docker/remote/version.rb
31
32
  homepage: http://github.com/getkuby/docker-remote