docker_registry2 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: c4099f30821a379920c714d54c5b56d4667e2352
4
- data.tar.gz: 8e6499d2478b76b023badaec87e0899709549bde
3
+ metadata.gz: cce22be352c28fdedb18bd5e760f223dfcbe3e01
4
+ data.tar.gz: 3b50ea0a5a5a4bd01413b644969db483cc03ef49
5
5
  SHA512:
6
- metadata.gz: 7ad53f9dfec49a1ecfc3458b5177ed35c824cd473fd3e5e421497b56a1ca91a8a84f47a8cbd0e3fbd064d2d2304ac675b838bd5d5adccce4429b483810421a82
7
- data.tar.gz: a5c640a9a73dd85cf81d996b70928afdc82524b667d9bec61d1396eb95fb3f8e973e137c39961ab1cbd319339d2462b679c1a7099d6895820d880ff1619034c2
6
+ metadata.gz: 59f287a1eef0adad31468e3f3568267bfcd6143c7a6d0edde031ae6c2be0922deecd60b27dfce4acab1689bb6b06429f4c357af3dcd5d0a297193696f940fc38
7
+ data.tar.gz: 1b1282ee6b00ac909af0bf478070f67aea287f1463e8dab2ff579a00a53cab19c210d08fb50b749feea6c8a48a2ab6045744f6b7900ecb82626683bb25772527
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v1.2.0, 15 October 2017
2
+
3
+ - Add shorter default timeouts. Previously, the RestClient default of 60 seconds
4
+ was used for both open_timeout and read_timeout. Now, those values are set at
5
+ 2 seconds and 5 seconds, respectively.
6
+
1
7
  ## v1.1.0, 13 October 2017
2
8
 
3
9
  - Move `ping` call from `DockerRegistry2::Registry.new` to
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Introduction
4
4
 
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.
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** require docker installed on your system to provide access.
6
6
 
7
7
  ````ruby
8
8
  reg = DockerRegistry2.connect("https://my.registy.corp.com")
@@ -46,7 +46,14 @@ reg = DockerRegistry2.connect("https://my.registy.corp.com")
46
46
 
47
47
  If you do not provide the URL for a registry, it uses the default `https://registry.hub.docker.com`.
48
48
 
49
+ By default, requests to the registry will timeout if they take over 2 seconds to
50
+ connect or over 5 seconds to respond. You can set different thresholds when
51
+ connecting to a registry as follows:
49
52
 
53
+ ```ruby
54
+ opts = { open_timeout: 2, read_timeout: 5 }
55
+ reg = DockerRegistry2.connect("https://my.registy.corp.com", opts)
56
+ ```
50
57
 
51
58
  You can connect anonymously or with credentials:
52
59
 
@@ -7,11 +7,15 @@ class DockerRegistry2::Registry
7
7
  # @param [Hash] options Client options
8
8
  # @option options [#to_s] :user User name for basic authentication
9
9
  # @option options [#to_s] :password Password for basic authentication
10
+ # @option options [#to_s] :open_timeout Time to wait for a connection with a registry
11
+ # @option options [#to_s] :read_timeout Time to wait for data from a registry
10
12
  def initialize(uri, options = {})
11
13
  @uri = URI.parse(uri)
12
14
  @base_uri = "#{@uri.scheme}://#{@uri.host}:#{@uri.port}"
13
15
  @user = options[:user]
14
16
  @password = options[:password]
17
+ @open_timeout = options[:open_timeout] || 2
18
+ @read_timeout = options[:read_timeout] || 5
15
19
  end
16
20
 
17
21
  def doget(url)
@@ -126,7 +130,14 @@ class DockerRegistry2::Registry
126
130
  stream.write chunk
127
131
  end
128
132
  }
129
- response = RestClient::Request.execute method: type, url: @base_uri+url, headers: {Accept: 'application/vnd.docker.distribution.manifest.v2+json'}, block_response: block
133
+ response = RestClient::Request.execute(
134
+ method: type,
135
+ url: @base_uri+url,
136
+ headers: {Accept: 'application/vnd.docker.distribution.manifest.v2+json'},
137
+ block_response: block,
138
+ open_timeout: @open_timeout,
139
+ read_timeout: @read_timeout
140
+ )
130
141
  rescue SocketError
131
142
  raise DockerRegistry2::RegistryUnknownException
132
143
  rescue RestClient::Unauthorized => e
@@ -151,7 +162,16 @@ class DockerRegistry2::Registry
151
162
  stream.write chunk
152
163
  end
153
164
  }
154
- 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
165
+ response = RestClient::Request.execute(
166
+ method: type,
167
+ url: @base_uri+url,
168
+ user: @user,
169
+ password: @password,
170
+ headers: {Accept: 'application/vnd.docker.distribution.manifest.v2+json'},
171
+ block_response: block,
172
+ open_timeout: @open_timeout,
173
+ read_timeout: @read_timeout
174
+ )
155
175
  rescue SocketError
156
176
  raise DockerRegistry2::RegistryUnknownException
157
177
  rescue RestClient::Unauthorized
@@ -170,7 +190,14 @@ class DockerRegistry2::Registry
170
190
  stream.write chunk
171
191
  end
172
192
  }
173
- 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
193
+ response = RestClient::Request.execute(
194
+ method: type,
195
+ url: @base_uri+url,
196
+ headers: {Authorization: 'Bearer '+token, Accept: 'application/vnd.docker.distribution.manifest.v2+json'},
197
+ block_response: block,
198
+ open_timeout: @open_timeout,
199
+ read_timeout: @read_timeout
200
+ )
174
201
  rescue SocketError
175
202
  raise DockerRegistry2::RegistryUnknownException
176
203
  rescue RestClient::Unauthorized
@@ -192,7 +219,14 @@ class DockerRegistry2::Registry
192
219
  # authenticate against the realm
193
220
  uri = URI.parse(target[:realm])
194
221
  begin
195
- response = RestClient::Request.execute method: :get, url: uri.to_s, headers: {params: target[:params]}, user: @user, password: @password
222
+ response = RestClient::Request.execute(
223
+ method: :get,
224
+ url: uri.to_s, headers: {params: target[:params]},
225
+ user: @user,
226
+ password: @password,
227
+ open_timeout: @open_timeout,
228
+ read_timeout: @read_timeout
229
+ )
196
230
  rescue RestClient::Unauthorized
197
231
  # bad authentication
198
232
  raise DockerRegistry2::RegistryAuthenticationException
@@ -1,3 +1,3 @@
1
1
  module DockerRegistry2
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avi Deitcher https://github.com/deitch
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-10-14 00:00:00.000000000 Z
13
+ date: 2017-10-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler