docker-remote 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -0
- data/lib/docker/remote.rb +1 -0
- data/lib/docker/remote/client.rb +42 -18
- data/lib/docker/remote/no_auth.rb +11 -0
- data/lib/docker/remote/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbe61af8e8709e3a11eb1df8bc561477d38c3540ce2d216bc81dc999d31822cf
|
4
|
+
data.tar.gz: 65a9d5336374a275246dc6ba950c3a4288823286ae1884f43f5a5bb748348c50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d04a849e0fe6fda791f19be79f7664a95f3c24c7b6a38c7b2f0831a9af09690c825c54b3a62c8477da65ac06902bb9bce712427c62dfbe8b619d4a9d24ad098
|
7
|
+
data.tar.gz: e927985c4d0a6b767941ce5ac77647c8e1c5e6c45446221fd3f237cfbf4f29754a54cf9eb08db6597aa694fb3f2eb8611d9660280771a8819fe82446c93568b5
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/lib/docker/remote.rb
CHANGED
@@ -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
|
data/lib/docker/remote/client.rb
CHANGED
@@ -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
|
57
|
-
when '
|
58
|
-
|
59
|
-
when '
|
60
|
-
|
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
|
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 ||=
|
73
|
-
|
74
|
-
|
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
|
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.
|
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-
|
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
|