docker-remote 0.3.0 → 0.4.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: fbe61af8e8709e3a11eb1df8bc561477d38c3540ce2d216bc81dc999d31822cf
4
- data.tar.gz: 65a9d5336374a275246dc6ba950c3a4288823286ae1884f43f5a5bb748348c50
3
+ metadata.gz: 6cfe49856e12add82e0b4fa76a42381640b46ab0810a08db03cbd4e6619fa8d5
4
+ data.tar.gz: d5d7ab9eb55c7d2189ab5127e5b9c03a5e3c2c53a16241e540907cce3158fc72
5
5
  SHA512:
6
- metadata.gz: 6d04a849e0fe6fda791f19be79f7664a95f3c24c7b6a38c7b2f0831a9af09690c825c54b3a62c8477da65ac06902bb9bce712427c62dfbe8b619d4a9d24ad098
7
- data.tar.gz: e927985c4d0a6b767941ce5ac77647c8e1c5e6c45446221fd3f237cfbf4f29754a54cf9eb08db6597aa694fb3f2eb8611d9660280771a8819fe82446c93568b5
6
+ metadata.gz: 046f4aa7357778f0ded105562fd8ec55e25dc4d012e1c9fcfd01ee4bda47670b26cb83a9fc1bb5f3b4ed625a248af8ea541effceb93e284984c1219baabe634e
7
+ data.tar.gz: 38cd75b59a2a12e2339fff98a492f97851d28068184dc7b354ef080f70a7e65baf09a5ffe6fc0495d64158e74d58e4826ceec90da75a2ca28535cbbb6d2a8ffd
@@ -1,3 +1,6 @@
1
+ ## 0.4.0
2
+ * Support redirection when making HTTP requests.
3
+
1
4
  ## 0.3.0
2
5
  * Support registries with no auth.
3
6
  * Raise errors upon receiving unexpected response codes during auth flow.
@@ -21,22 +21,19 @@ module Docker
21
21
  end
22
22
 
23
23
  def tags
24
- request = auth.make_get("/v2/#{repo}/tags/list")
25
- response = registry_http.request(request)
24
+ response = get("/v2/#{repo}/tags/list")
26
25
  potentially_raise_error!(response)
27
26
  JSON.parse(response.body)['tags']
28
27
  end
29
28
 
30
29
  def manifest_for(reference)
31
- request = auth.make_get("/v2/#{repo}/manifests/#{reference}")
32
- response = registry_http.request(request)
30
+ response = get("/v2/#{repo}/manifests/#{reference}")
33
31
  potentially_raise_error!(response)
34
32
  JSON.parse(response.body)
35
33
  end
36
34
 
37
35
  def catalog
38
- request = auth.make_get("/v2/_catalog")
39
- response = registry_http.request(request)
36
+ response = get("/v2/_catalog")
40
37
  potentially_raise_error!(response)
41
38
  JSON.parse(response.body)
42
39
  end
@@ -45,8 +42,7 @@ module Docker
45
42
 
46
43
  def auth
47
44
  @auth ||= begin
48
- request = Net::HTTP::Get.new('/v2/')
49
- response = registry_http.request(request)
45
+ response = get('/v2/', use_auth: nil)
50
46
 
51
47
  case response.code
52
48
  when '200'
@@ -87,15 +83,47 @@ module Docker
87
83
  end
88
84
  end
89
85
 
86
+ def get(path, http: registry_http, use_auth: auth, limit: 5)
87
+ if limit == 0
88
+ raise DockerRemoteError, 'too many redirects'
89
+ end
90
+
91
+ request = if use_auth
92
+ use_auth.make_get(path)
93
+ else
94
+ Net::HTTP::Get.new(path)
95
+ end
96
+
97
+ response = http.request(request)
98
+
99
+ case response
100
+ when Net::HTTPRedirection
101
+ redirect_uri = URI.parse(response['location'])
102
+ redirect_http = make_http(redirect_uri)
103
+ return get(
104
+ redirect_uri.path, {
105
+ http: redirect_http,
106
+ use_auth: use_auth,
107
+ limit: limit - 1
108
+ }
109
+ )
110
+ end
111
+
112
+ response
113
+ end
114
+
90
115
  def registry_uri
91
116
  @registry_uri ||= URI.parse(registry_url)
92
117
  end
93
118
 
119
+ def make_http(uri)
120
+ Net::HTTP.new(uri.host, uri.port).tap do |http|
121
+ http.use_ssl = true if uri.scheme == 'https'
122
+ end
123
+ end
124
+
94
125
  def registry_http
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
126
+ @registry_http ||= make_http(registry_uri)
99
127
  end
100
128
  end
101
129
  end
@@ -1,5 +1,5 @@
1
1
  module Docker
2
2
  module Remote
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.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.3.0
4
+ version: 0.4.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-29 00:00:00.000000000 Z
11
+ date: 2020-11-02 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: