docker_registry2 0.3.0 → 0.4.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/README.md +14 -6
- data/docker_registry2.gemspec +2 -2
- data/lib/docker_registry2.rb +2 -2
- data/lib/registry/exceptions.rb +1 -1
- data/lib/registry/registry.rb +34 -19
- data/lib/registry/version.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c827b61fd48f2bd6359d119f56abcc48be8ccf57
|
4
|
+
data.tar.gz: b73fec0b836cbb3930a44e830c8ef44664d63cd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb535e5baa99262fd1a5819a9df3bdf7c9d98a8b13782c1dfecaeff1a05071e9b4c16e9df0d6f6a25749434f5a7280617f7dab458e6b08f94e60bc1c3909cf68
|
7
|
+
data.tar.gz: ba4f8dfaa9ef8b3210d317f5cb9d843fc21b60e2a15101f609adb0118ced20b2c8b73ebdf29d0f5d2ee2501aadb6dc8c8f947d27eef016108de357a4cbb23d38
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
This is a simple gem that provides direct http access to a docker registry v2 without going through a docker server. You do **not** requires docker installed on your system to provide access.
|
6
6
|
|
7
7
|
````ruby
|
8
|
-
reg =
|
8
|
+
reg = DockerRegistry2.connect("https://my.registy.corp.com")
|
9
9
|
repos = reg.search("foo/repo")
|
10
10
|
tags = reg.tags("foo/repo")
|
11
11
|
````
|
@@ -14,12 +14,20 @@ Supports anonymous access, http authorization and v2 token access.
|
|
14
14
|
|
15
15
|
Inspired by https://github.com/rosylilly/docker_registry but written separately.
|
16
16
|
|
17
|
+
#### Note
|
18
|
+
|
19
|
+
Prior to version 0.4.0, the name used was DockerRegistry. As of 0.4.0 it is DockerRegistry2.
|
20
|
+
If you still need DockerRegistry, just create an alias with:
|
21
|
+
|
22
|
+
````ruby
|
23
|
+
DockerRegistry = DockerRegistry2
|
24
|
+
````
|
17
25
|
|
18
26
|
## Installation
|
19
27
|
|
20
28
|
Add the following to your Gemfile:
|
21
29
|
|
22
|
-
gem 'docker_registry2
|
30
|
+
gem 'docker_registry2'
|
23
31
|
|
24
32
|
And execute:
|
25
33
|
|
@@ -35,7 +43,7 @@ Once it is installed, you first *open* a connection to a registry, and then *req
|
|
35
43
|
To connect to a registry:
|
36
44
|
|
37
45
|
````ruby
|
38
|
-
reg =
|
46
|
+
reg = DockerRegistry2.connect("https://my.registy.corp.com")
|
39
47
|
````
|
40
48
|
|
41
49
|
The above will connect anonymously to the registry via the endpoint `https://my.registry.corp.com/v2/`.
|
@@ -50,7 +58,7 @@ The following exceptions are thrown:
|
|
50
58
|
If you wish to authenticate, pass a username and password as part of the URL.
|
51
59
|
|
52
60
|
````ruby
|
53
|
-
reg =
|
61
|
+
reg = DockerRegistry2.connect("https://myuser:mypass@my.registy.corp.com")
|
54
62
|
````
|
55
63
|
|
56
64
|
The following exceptions are thrown:
|
@@ -62,7 +70,7 @@ The following exceptions are thrown:
|
|
62
70
|
|
63
71
|
|
64
72
|
### Requests
|
65
|
-
Once you have a valid `reg` object return by `
|
73
|
+
Once you have a valid `reg` object return by `DockerRegistry2.connect()`, you can make requests. As of this version, only search and tags are supported. Others will be added over time.
|
66
74
|
|
67
75
|
|
68
76
|
#### search
|
@@ -239,7 +247,7 @@ The following exceptions are thrown:
|
|
239
247
|
|
240
248
|
### Exceptions
|
241
249
|
|
242
|
-
All exceptions thrown inherit from `
|
250
|
+
All exceptions thrown inherit from `DockerRegistry2::Exception`.
|
243
251
|
|
244
252
|
## Tests
|
245
253
|
The simplest way to test is against a true v2 registry. Thus, the test setup and teardown work against a docker registry. That means that to test, you need a docker engine running. The tests will start up a registry (actually, two registries, to be able to test `copy()`), initialize the data and test against them.
|
data/docker_registry2.gemspec
CHANGED
@@ -5,8 +5,8 @@ require 'registry/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'docker_registry2'
|
8
|
-
spec.version =
|
9
|
-
spec.authors = ['Avi Deitcher https://github.com/deitch', 'Jonathan Hurter https://github.com/johnsudaar']
|
8
|
+
spec.version = DockerRegistry2::VERSION
|
9
|
+
spec.authors = ['Avi Deitcher https://github.com/deitch', 'Jonathan Hurter https://github.com/johnsudaar', 'Dmitry Fleytman https://github.com/dmitryfleytman']
|
10
10
|
spec.summary = 'Docker v2 registry HTTP API client'
|
11
11
|
spec.description = 'Docker v2 registry HTTP API client with support for token authentication'
|
12
12
|
spec.homepage = 'https://github.com/deitch/docker_registry2'
|
data/lib/docker_registry2.rb
CHANGED
@@ -3,9 +3,9 @@ require File.dirname(__FILE__) + '/registry/registry'
|
|
3
3
|
require File.dirname(__FILE__) + '/registry/exceptions'
|
4
4
|
|
5
5
|
|
6
|
-
module
|
6
|
+
module DockerRegistry2
|
7
7
|
def self.connect(uri)
|
8
|
-
@reg =
|
8
|
+
@reg = DockerRegistry2::Registry.new(uri)
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.search(query = '')
|
data/lib/registry/exceptions.rb
CHANGED
data/lib/registry/registry.rb
CHANGED
@@ -2,7 +2,7 @@ require 'fileutils'
|
|
2
2
|
require 'rest-client'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
class
|
5
|
+
class DockerRegistry2::Registry
|
6
6
|
# @param [#to_s] base_uri Docker registry base URI
|
7
7
|
# @param [Hash] options Client options
|
8
8
|
# @option options [#to_s] :user User name for basic authentication
|
@@ -53,7 +53,7 @@ class DockerRegistry::Registry
|
|
53
53
|
else
|
54
54
|
begin
|
55
55
|
head = dohead "/v2/#{repo}/manifests/#{tag}"
|
56
|
-
rescue
|
56
|
+
rescue DockerRegistry2::InvalidMethod
|
57
57
|
# in case we are in a registry pre-2.3.0, which did not support manifest HEAD
|
58
58
|
useGet = true
|
59
59
|
head = doget "/v2/#{repo}/manifests/#{tag}"
|
@@ -95,49 +95,64 @@ class DockerRegistry::Registry
|
|
95
95
|
end
|
96
96
|
|
97
97
|
private
|
98
|
-
def doreq(type,url)
|
98
|
+
def doreq(type,url,stream=nil)
|
99
99
|
begin
|
100
|
-
|
100
|
+
block = stream.nil? ? nil : proc { |response|
|
101
|
+
response.read_body do |chunk|
|
102
|
+
stream.write chunk
|
103
|
+
end
|
104
|
+
}
|
105
|
+
response = RestClient::Request.execute method: type, url: @base_uri+url, headers: {Accept: 'application/vnd.docker.distribution.manifest.v2+json'}, block_response: block
|
101
106
|
rescue SocketError
|
102
|
-
raise
|
107
|
+
raise DockerRegistry2::RegistryUnknownException
|
103
108
|
rescue RestClient::Unauthorized => e
|
104
109
|
header = e.response.headers[:www_authenticate]
|
105
110
|
method = header.downcase.split(' ')[0]
|
106
111
|
case method
|
107
112
|
when 'basic'
|
108
|
-
response = do_basic_req(type, url)
|
113
|
+
response = do_basic_req(type, url, stream)
|
109
114
|
when 'bearer'
|
110
|
-
response = do_bearer_req(type, url, header)
|
115
|
+
response = do_bearer_req(type, url, header, stream)
|
111
116
|
else
|
112
|
-
raise
|
117
|
+
raise DockerRegistry2::RegistryUnknownException
|
113
118
|
end
|
114
119
|
end
|
115
120
|
return response
|
116
121
|
end
|
117
122
|
|
118
|
-
def do_basic_req(type, url)
|
123
|
+
def do_basic_req(type, url, stream=nil)
|
119
124
|
begin
|
120
|
-
|
125
|
+
block = stream.nil? ? nil : proc { |response|
|
126
|
+
response.read_body do |chunk|
|
127
|
+
stream.write chunk
|
128
|
+
end
|
129
|
+
}
|
130
|
+
response = RestClient::Request.execute method: type, url: @base_uri+url, user: @user, password: @password, headers: {Accept: 'application/vnd.docker.distribution.manifest.v2+json'}, block_response: block
|
121
131
|
rescue SocketError
|
122
|
-
raise
|
132
|
+
raise DockerRegistry2::RegistryUnknownException
|
123
133
|
rescue RestClient::Unauthorized
|
124
|
-
raise
|
134
|
+
raise DockerRegistry2::RegistryAuthenticationException
|
125
135
|
rescue RestClient::MethodNotAllowed
|
126
|
-
raise
|
136
|
+
raise DockerRegistry2::InvalidMethod
|
127
137
|
end
|
128
138
|
return response
|
129
139
|
end
|
130
140
|
|
131
|
-
def do_bearer_req(type, url, header)
|
141
|
+
def do_bearer_req(type, url, header, stream=false)
|
132
142
|
token = authenticate_bearer(header)
|
133
143
|
begin
|
134
|
-
|
144
|
+
block = stream.nil? ? nil : proc { |response|
|
145
|
+
response.read_body do |chunk|
|
146
|
+
stream.write chunk
|
147
|
+
end
|
148
|
+
}
|
149
|
+
response = RestClient::Request.execute method: type, url: @base_uri+url, headers: {Authorization: 'Bearer '+token, Accept: 'application/vnd.docker.distribution.manifest.v2+json'}, block_response: block
|
135
150
|
rescue SocketError
|
136
|
-
raise
|
151
|
+
raise DockerRegistry2::RegistryUnknownException
|
137
152
|
rescue RestClient::Unauthorized
|
138
|
-
raise
|
153
|
+
raise DockerRegistry2::RegistryAuthenticationException
|
139
154
|
rescue RestClient::MethodNotAllowed
|
140
|
-
raise
|
155
|
+
raise DockerRegistry2::InvalidMethod
|
141
156
|
end
|
142
157
|
|
143
158
|
return response
|
@@ -158,7 +173,7 @@ class DockerRegistry::Registry
|
|
158
173
|
response = RestClient.get uri.to_s, {params: target[:params]}
|
159
174
|
rescue RestClient::Unauthorized
|
160
175
|
# bad authentication
|
161
|
-
raise
|
176
|
+
raise DockerRegistry2::RegistryAuthenticationException
|
162
177
|
end
|
163
178
|
# now save the web token
|
164
179
|
return JSON.parse(response)["token"]
|
data/lib/registry/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = '0.
|
1
|
+
module DockerRegistry2
|
2
|
+
VERSION = '0.4.0'
|
3
3
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker_registry2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avi Deitcher https://github.com/deitch
|
8
8
|
- Jonathan Hurter https://github.com/johnsudaar
|
9
|
+
- Dmitry Fleytman https://github.com/dmitryfleytman
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2017-02-27 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: bundler
|
@@ -101,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
version: '0'
|
102
103
|
requirements: []
|
103
104
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.4.
|
105
|
+
rubygems_version: 2.4.8
|
105
106
|
signing_key:
|
106
107
|
specification_version: 4
|
107
108
|
summary: Docker v2 registry HTTP API client
|
108
109
|
test_files: []
|
109
|
-
has_rdoc:
|