docker-remote 0.1.0 → 0.2.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 +3 -0
- data/LICENSE +21 -0
- data/docker-remote.gemspec +2 -2
- data/lib/docker/remote.rb +10 -4
- data/lib/docker/remote/basic_auth.rb +20 -0
- data/lib/docker/remote/bearer_auth.rb +55 -0
- data/lib/docker/remote/client.rb +17 -53
- data/lib/docker/remote/utils.rb +21 -0
- data/lib/docker/remote/version.rb +1 -1
- metadata +12 -9
- data/lib/docker/remote/server_auth.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19acf54d628fdf18296c7a86ffdd6760840f7222fa28e5438e5b0edc7bac7136
|
4
|
+
data.tar.gz: 1ce08796037731c708c9f5ce79e8038d31d288654f0ea7070166a2d6ac4e711c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 273f430350900735e9efb3a63155d01d32d14afcc7ab5b34b94250e2de0d12c2cd5301f88d08c0729513848f06a559b918d7a762a0b1803854c6f8069e9263f3
|
7
|
+
data.tar.gz: 60684d86a0675c3465455b3df6373144db0894a908fd5c0491c5b822a7c5544d00dd50121a3d57d666ea4b5a4b0a4a34b674c29bd6e25e690c142217a63c60d0
|
data/CHANGELOG.md
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Cameron Dutro
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/docker-remote.gemspec
CHANGED
@@ -8,10 +8,10 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.email = ['camertron@gmail.com']
|
9
9
|
s.homepage = 'http://github.com/getkuby/docker-remote'
|
10
10
|
|
11
|
-
s.description = s.summary = 'A Ruby client for communicating with the Docker
|
11
|
+
s.description = s.summary = 'A Ruby client for communicating with the Docker registry API v2.'
|
12
12
|
|
13
13
|
s.platform = Gem::Platform::RUBY
|
14
14
|
|
15
15
|
s.require_path = 'lib'
|
16
|
-
s.files = Dir['{lib,spec}/**/*', 'Gemfile', 'CHANGELOG.md', 'README.md', 'Rakefile', 'docker-remote.gemspec']
|
16
|
+
s.files = Dir['{lib,spec}/**/*', 'Gemfile', 'CHANGELOG.md', 'LICENSE', 'README.md', 'Rakefile', 'docker-remote.gemspec']
|
17
17
|
end
|
data/lib/docker/remote.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
|
4
1
|
module Docker
|
5
2
|
module Remote
|
3
|
+
class ClientError < StandardError; end
|
4
|
+
class ServerError < StandardError; end
|
5
|
+
class UnauthorizedError < ClientError; end
|
6
|
+
class NotFoundError < ClientError; end
|
7
|
+
|
8
|
+
class UnsupportedAuthTypeError < StandardError; end
|
9
|
+
|
10
|
+
autoload :BasicAuth, 'docker/remote/basic_auth'
|
11
|
+
autoload :BearerAuth, 'docker/remote/bearer_auth'
|
6
12
|
autoload :Client, 'docker/remote/client'
|
7
|
-
autoload :
|
13
|
+
autoload :Utils, 'docker/remote/utils'
|
8
14
|
end
|
9
15
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Docker
|
4
|
+
module Remote
|
5
|
+
class BasicAuth
|
6
|
+
attr_reader :username, :password
|
7
|
+
|
8
|
+
def initialize(username, password)
|
9
|
+
@username = username
|
10
|
+
@password = password
|
11
|
+
end
|
12
|
+
|
13
|
+
def make_get(path)
|
14
|
+
Net::HTTP::Get.new(path).tap do |request|
|
15
|
+
request.basic_auth(username, password)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Docker
|
6
|
+
module Remote
|
7
|
+
class BearerAuth
|
8
|
+
include Utils
|
9
|
+
|
10
|
+
attr_reader :params, :repo, :username, :password
|
11
|
+
|
12
|
+
def initialize(params, repo, username, password)
|
13
|
+
@params = params
|
14
|
+
@repo = repo
|
15
|
+
@username = username
|
16
|
+
@password = password
|
17
|
+
end
|
18
|
+
|
19
|
+
def make_get(path)
|
20
|
+
Net::HTTP::Get.new(path).tap do |request|
|
21
|
+
request['Authorization'] = "Bearer #{token}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def realm
|
28
|
+
@realm ||= URI.parse(params['realm'])
|
29
|
+
end
|
30
|
+
|
31
|
+
def service
|
32
|
+
@serivce ||= params['service']
|
33
|
+
end
|
34
|
+
|
35
|
+
def token
|
36
|
+
@token ||= begin
|
37
|
+
http = Net::HTTP.new(realm.host, realm.port)
|
38
|
+
http.use_ssl = true if realm.scheme == 'https'
|
39
|
+
|
40
|
+
request = Net::HTTP::Get.new(
|
41
|
+
"#{realm.request_uri}?service=#{service}&scope=repository:#{repo}:pull"
|
42
|
+
)
|
43
|
+
|
44
|
+
if username && password
|
45
|
+
request.basic_auth(username, password)
|
46
|
+
end
|
47
|
+
|
48
|
+
response = http.request(request)
|
49
|
+
potentially_raise_error!(response)
|
50
|
+
JSON.parse(response.body)['token']
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/docker/remote/client.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
2
4
|
|
3
5
|
module Docker
|
4
6
|
module Remote
|
5
|
-
class ClientError < StandardError; end
|
6
|
-
class ServerError < StandardError; end
|
7
|
-
class UnauthorizedError < ClientError; end
|
8
|
-
class NotFoundError < ClientError; end
|
9
|
-
|
10
7
|
class Client
|
8
|
+
include Utils
|
9
|
+
|
11
10
|
attr_reader :registry_url, :repo, :username, :password
|
12
11
|
|
13
12
|
def initialize(registry_url, repo, username = nil, password = nil)
|
@@ -18,21 +17,21 @@ module Docker
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def tags
|
21
|
-
request = make_get("/v2/#{repo}/tags/list")
|
20
|
+
request = auth.make_get("/v2/#{repo}/tags/list")
|
22
21
|
response = registry_http.request(request)
|
23
22
|
potentially_raise_error!(response)
|
24
23
|
JSON.parse(response.body)['tags']
|
25
24
|
end
|
26
25
|
|
27
26
|
def manifest_for(reference)
|
28
|
-
request = make_get("/v2/#{repo}/manifests/#{reference}")
|
27
|
+
request = auth.make_get("/v2/#{repo}/manifests/#{reference}")
|
29
28
|
response = registry_http.request(request)
|
30
29
|
potentially_raise_error!(response)
|
31
30
|
JSON.parse(response.body)
|
32
31
|
end
|
33
32
|
|
34
33
|
def catalog
|
35
|
-
request = make_get("/v2/_catalog")
|
34
|
+
request = auth.make_get("/v2/_catalog")
|
36
35
|
response = registry_http.request(request)
|
37
36
|
potentially_raise_error!(response)
|
38
37
|
JSON.parse(response.body)
|
@@ -40,28 +39,8 @@ module Docker
|
|
40
39
|
|
41
40
|
private
|
42
41
|
|
43
|
-
def
|
44
|
-
@
|
45
|
-
uri = URI.parse(server_auth.realm)
|
46
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
47
|
-
http.use_ssl = true if uri.scheme == 'https'
|
48
|
-
|
49
|
-
request = Net::HTTP::Get.new(
|
50
|
-
"#{uri.request_uri}?service=#{server_auth.service}&scope=repository:#{repo}:pull"
|
51
|
-
)
|
52
|
-
|
53
|
-
if username && password
|
54
|
-
request.basic_auth(username, password)
|
55
|
-
end
|
56
|
-
|
57
|
-
response = http.request(request)
|
58
|
-
potentially_raise_error!(response)
|
59
|
-
JSON.parse(response.body)['token']
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def server_auth
|
64
|
-
@server_auth ||= begin
|
42
|
+
def auth
|
43
|
+
@auth ||= begin
|
65
44
|
request = Net::HTTP::Get.new('/v2/')
|
66
45
|
response = registry_http.request(request)
|
67
46
|
auth = response['www-authenticate']
|
@@ -74,7 +53,14 @@ module Docker
|
|
74
53
|
ret[key.strip] = value.strip[1..-2] # remove quotes
|
75
54
|
end
|
76
55
|
|
77
|
-
|
56
|
+
case auth_type.downcase
|
57
|
+
when 'bearer'
|
58
|
+
BearerAuth.new(params, repo, username, password)
|
59
|
+
when 'basic'
|
60
|
+
BasicAuth.new(username, password)
|
61
|
+
else
|
62
|
+
raise UnsupportedAuthTypeError, "unsupported Docker auth type '#{auth_type}'"
|
63
|
+
end
|
78
64
|
end
|
79
65
|
end
|
80
66
|
|
@@ -87,28 +73,6 @@ module Docker
|
|
87
73
|
http.use_ssl = true if registry_uri.scheme == 'https'
|
88
74
|
end
|
89
75
|
end
|
90
|
-
|
91
|
-
def make_get(path)
|
92
|
-
Net::HTTP::Get.new(path).tap do |request|
|
93
|
-
request['Authorization'] = "Bearer #{token}"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def potentially_raise_error!(response)
|
98
|
-
case response.code.to_i
|
99
|
-
when 401
|
100
|
-
raise UnauthorizedError, "401 Unauthorized: #{response.message}"
|
101
|
-
when 404
|
102
|
-
raise NotFoundError, "404 Not Found: #{response.message}"
|
103
|
-
end
|
104
|
-
|
105
|
-
case response.code.to_i / 100
|
106
|
-
when 4
|
107
|
-
raise ClientError, "#{response.code}: #{response.message}"
|
108
|
-
when 5
|
109
|
-
raise ServerError, "#{response.code}: #{response.message}"
|
110
|
-
end
|
111
|
-
end
|
112
76
|
end
|
113
77
|
end
|
114
78
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Docker
|
2
|
+
module Remote
|
3
|
+
module Utils
|
4
|
+
def potentially_raise_error!(response)
|
5
|
+
case response.code.to_i
|
6
|
+
when 401
|
7
|
+
raise UnauthorizedError, "401 Unauthorized: #{response.message}"
|
8
|
+
when 404
|
9
|
+
raise NotFoundError, "404 Not Found: #{response.message}"
|
10
|
+
end
|
11
|
+
|
12
|
+
case response.code.to_i / 100
|
13
|
+
when 4
|
14
|
+
raise ClientError, "#{response.code}: #{response.message}"
|
15
|
+
when 5
|
16
|
+
raise ServerError, "#{response.code}: #{response.message}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker-remote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: A Ruby client for communicating with the Docker
|
13
|
+
description: A Ruby client for communicating with the Docker registry API v2.
|
14
14
|
email:
|
15
15
|
- camertron@gmail.com
|
16
16
|
executables: []
|
@@ -19,16 +19,19 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- CHANGELOG.md
|
21
21
|
- Gemfile
|
22
|
+
- LICENSE
|
22
23
|
- Rakefile
|
23
24
|
- docker-remote.gemspec
|
24
25
|
- lib/docker/remote.rb
|
26
|
+
- lib/docker/remote/basic_auth.rb
|
27
|
+
- lib/docker/remote/bearer_auth.rb
|
25
28
|
- lib/docker/remote/client.rb
|
26
|
-
- lib/docker/remote/
|
29
|
+
- lib/docker/remote/utils.rb
|
27
30
|
- lib/docker/remote/version.rb
|
28
31
|
homepage: http://github.com/getkuby/docker-remote
|
29
32
|
licenses: []
|
30
33
|
metadata: {}
|
31
|
-
post_install_message:
|
34
|
+
post_install_message:
|
32
35
|
rdoc_options: []
|
33
36
|
require_paths:
|
34
37
|
- lib
|
@@ -43,8 +46,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
46
|
- !ruby/object:Gem::Version
|
44
47
|
version: '0'
|
45
48
|
requirements: []
|
46
|
-
rubygems_version: 3.
|
47
|
-
signing_key:
|
49
|
+
rubygems_version: 3.1.4
|
50
|
+
signing_key:
|
48
51
|
specification_version: 4
|
49
|
-
summary: A Ruby client for communicating with the Docker
|
52
|
+
summary: A Ruby client for communicating with the Docker registry API v2.
|
50
53
|
test_files: []
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Docker
|
2
|
-
module Remote
|
3
|
-
class ServerAuth
|
4
|
-
attr_reader :auth_type, :params
|
5
|
-
|
6
|
-
def initialize(auth_type, params)
|
7
|
-
@auth_type = auth_type
|
8
|
-
@params = params
|
9
|
-
end
|
10
|
-
|
11
|
-
def realm
|
12
|
-
@params['realm']
|
13
|
-
end
|
14
|
-
|
15
|
-
def service
|
16
|
-
@params['service']
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|