docker_registry2 0.1.1 → 0.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: 923c330d2d2ca5572b95045747d9a3b4225a3a8d
4
- data.tar.gz: 7e8f2c73a181ffaf00a9d4702a055460923e9027
3
+ metadata.gz: ef04c903f6bb8dba1bfc577438ce0f9cb089c3bd
4
+ data.tar.gz: 2091e8b03ea16e4031fb57a4af74475689c7c07d
5
5
  SHA512:
6
- metadata.gz: 95bd7ccfed87e8b026014d0f40f03158b8091513b21c12391dae4c76dbafb805f547a55c90751a6cea80d5005e16972d84a896849649d87a45db2459825dfbbb
7
- data.tar.gz: dc89367f9f05456c82efb6050219c2c6ea00245f52725d3b9b738933adf81057efdf3e06c2d75d3fea21a646bd13371821cd0ec98b2e9d3222ecace1dd681c9e
6
+ metadata.gz: 57d618d30acabc7e70119fbe117db816b6b9680caffc0964acd0896f498ab5fa5fe332eb73fa15af46b879e7e7d3cd8a379fb4c9571905317be720e27641cdf9
7
+ data.tar.gz: ce03cf1323138987eb55b9a93edea4abe8006531b915398c539a8d87b9298c65ea9c018c096669eed30cc4fe18303ae7329045c29b638383de6984c633b2dd24
data/README.md CHANGED
@@ -118,6 +118,7 @@ MIT License.
118
118
  ## Contribution
119
119
 
120
120
  Developed by Avi Deitcher http://github.com/deitch
121
+ Contributors Jonathan Hurter https://github.com/johnsudaar
121
122
  Contributions courtesy of TraderTools, Inc. http://tradertools.com
122
123
 
123
124
 
@@ -6,7 +6,7 @@ require 'registry/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'docker_registry2'
8
8
  spec.version = DockerRegistry::VERSION
9
- spec.authors = ['Avi Deitcher']
9
+ spec.authors = ['Avi Deitcher https://github.com/deitch', 'Jonathan Hurter https://github.com/johnsudaar']
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'
@@ -14,34 +14,53 @@ class DockerRegistry::Registry
14
14
  # make a ping connection
15
15
  ping
16
16
  end
17
-
18
- def doget(url, token=nil)
17
+
18
+ def doget(url)
19
19
  begin
20
- # do we already have a token to authenticate?
21
- if token.nil?
22
- response = RestClient.get @base_uri+url
23
- else
24
- response = RestClient.get @base_uri+url, Authorization: 'Bearer '+token
25
- end
20
+ response = RestClient.get @base_uri+url
26
21
  rescue SocketError
27
22
  raise DockerRegistry::RegistryUnknownException
28
23
  rescue RestClient::Unauthorized => e
29
- # unauthorized
30
- # did we already try for this realm and service and scope and have insufficient privileges?
31
- if token.nil?
32
- token = authenticate e.response.headers[:www_authenticate]
33
- # go do whatever you were going to do again
34
- response = doget url, token
24
+ header = e.response.headers[:www_authenticate]
25
+ method = header.downcase.split(' ')[0]
26
+ case method
27
+ when 'basic'
28
+ response = do_basic_get(url)
29
+ when 'bearer'
30
+ response = do_bearer_get(url, header)
35
31
  else
36
- throw DockerRegistry::RegistryAuthorizationException
32
+ raise DockerRegistry::RegistryUnknownException
37
33
  end
38
- rescue RestClient::ResourceNotFound
34
+ end
35
+ return response
36
+ end
37
+
38
+ def do_basic_get(url)
39
+ begin
40
+ res = RestClient::Resource.new( @base_uri+url, @user, @password)
41
+ response = res.get
42
+ rescue SocketError
43
+ raise DockerRegistry::RegistryUnknownException
44
+ rescue RestClient::Unauthorized
45
+ raise DockerRegistry::RegistryAuthenticationException
46
+ end
47
+ return response
48
+ end
49
+
50
+ def do_bearer_get(url, header)
51
+ token = authenticate_bearer(header)
52
+ begin
53
+ response = RestClient.get @base_uri+url, Authorization: 'Bearer '+token
54
+ rescue SocketError
39
55
  raise DockerRegistry::RegistryUnknownException
56
+ rescue RestClient::Unauthorized
57
+ raise DockerRegistry::RegistryAuthenticationException
40
58
  end
59
+
41
60
  return response
42
61
  end
43
-
44
- def authenticate(header)
62
+
63
+ def authenticate_bearer(header)
45
64
  # get the parts we need
46
65
  target = split_auth_header(header)
47
66
  # did we have a username and password?
@@ -61,7 +80,7 @@ class DockerRegistry::Registry
61
80
  # now save the web token
62
81
  return JSON.parse(response)["token"]
63
82
  end
64
-
83
+
65
84
  def split_auth_header(header = '')
66
85
  h = Hash.new
67
86
  h = {params: {}}
@@ -81,7 +100,7 @@ class DockerRegistry::Registry
81
100
  def ping
82
101
  response = doget '/v2/'
83
102
  end
84
-
103
+
85
104
  def search(query = '')
86
105
  response = doget "/v2/_catalog"
87
106
  # parse the response
@@ -98,4 +117,4 @@ class DockerRegistry::Registry
98
117
  # parse the response
99
118
  JSON.parse response
100
119
  end
101
- end
120
+ end
@@ -1,3 +1,3 @@
1
1
  module DockerRegistry
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_registry2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Avi Deitcher
7
+ - Avi Deitcher https://github.com/deitch
8
+ - Jonathan Hurter https://github.com/johnsudaar
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []