Skip to content

Commit aab675a

Browse files
author
Matthew Fisher
committed
fix(controller): fix registry API calls
After upgrading the private registry to 0.6.8, there were some changes to the API that were missed. For example, the docker version is now mandatory[1]. If you have docker v0.10.0 or higher, there is also a checksum computation check done on each push, so I hardcoded the user-agent to v0.9.0. This is a stopgap until a) we update the API calls to v0.10.0 b) we replace this component with a docker-registry python package[2] [1]: docker-archive/docker-registry@64f4198 [2]: docker-archive/docker-registry#297 fixes #779
1 parent 6031b2c commit aab675a

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

controller/registry/private.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,26 @@ def _put_first_image(repository_path):
5959
_commit(repository_path, image, _empty_tar_archive(), 'v0')
6060

6161

62+
def _api_call(endpoint, data=None, headers={}, cookies=None, request_type='GET'):
63+
# FIXME: update API calls for docker 0.10.0+
64+
base_headers = {'user-agent': 'docker/0.9.0'}
65+
r = None
66+
if len(headers) > 0:
67+
for header, value in headers.iteritems():
68+
base_headers[header] = value
69+
if request_type == 'GET':
70+
r = requests.get(endpoint, headers=base_headers)
71+
elif request_type == 'PUT':
72+
r = requests.put(endpoint, data=data, headers=base_headers, cookies=cookies)
73+
else:
74+
raise AttributeError("request type not supported: {}".format(request_type))
75+
return r
76+
77+
6278
def _get_tag(repository, tag):
6379
path = "/v1/repositories/{repository}/tags/{tag}".format(**locals())
6480
url = urlparse.urljoin(settings.REGISTRY_URL, path)
65-
r = requests.get(url)
81+
r = _api_call(url)
6682
if not r.status_code == 200:
6783
raise RuntimeError("GET Image Error ({}: {})".format(r.status_code, r.text))
6884
print r.text
@@ -72,7 +88,7 @@ def _get_tag(repository, tag):
7288
def _get_image(image_id):
7389
path = "/v1/images/{image_id}/json".format(**locals())
7490
url = urlparse.urljoin(settings.REGISTRY_URL, path)
75-
r = requests.get(url)
91+
r = _api_call(url)
7692
if not r.status_code == 200:
7793
raise RuntimeError("GET Image Error ({}: {})".format(r.status_code, r.text))
7894
return r.json()
@@ -81,7 +97,7 @@ def _get_image(image_id):
8197
def _put_image(image):
8298
path = "/v1/images/{id}/json".format(**image)
8399
url = urlparse.urljoin(settings.REGISTRY_URL, path)
84-
r = requests.put(url, data=json.dumps(image))
100+
r = _api_call(url, data=json.dumps(image), request_type='PUT')
85101
if not r.status_code == 200:
86102
raise RuntimeError("PUT Image Error ({}: {})".format(r.status_code, r.text))
87103
return r.json()
@@ -90,7 +106,7 @@ def _put_image(image):
90106
def _put_layer(image_id, layer_fileobj):
91107
path = "/v1/images/{image_id}/layer".format(**locals())
92108
url = urlparse.urljoin(settings.REGISTRY_URL, path)
93-
r = requests.put(url, data=layer_fileobj.read())
109+
r = _api_call(url, data=layer_fileobj.read(), request_type='PUT')
94110
if not r.status_code == 200:
95111
raise RuntimeError("PUT Layer Error ({}: {})".format(r.status_code, r.text))
96112
return r.cookies
@@ -101,7 +117,7 @@ def _put_checksum(image, cookies):
101117
url = urlparse.urljoin(settings.REGISTRY_URL, path)
102118
tarsum = TarSum(json.dumps(image)).compute()
103119
headers = {'X-Docker-Checksum': tarsum}
104-
r = requests.put(url, headers=headers, cookies=cookies)
120+
r = _api_call(url, headers=headers, cookies=cookies, request_type='PUT')
105121
if not r.status_code == 200:
106122
raise RuntimeError("PUT Checksum Error ({}: {})".format(r.status_code, r.text))
107123
print r.json()
@@ -110,7 +126,7 @@ def _put_checksum(image, cookies):
110126
def _put_tag(image_id, repository_path, tag):
111127
path = "/v1/repositories/{repository_path}/tags/{tag}".format(**locals())
112128
url = urlparse.urljoin(settings.REGISTRY_URL, path)
113-
r = requests.put(url, data=json.dumps(image_id))
129+
r = _api_call(url, data=json.dumps(image_id), request_type='PUT')
114130
if not r.status_code == 200:
115131
raise RuntimeError("PUT Tag Error ({}: {})".format(r.status_code, r.text))
116132
print r.json()

0 commit comments

Comments
 (0)