def registry_get(self, api):
url = "https://%s/v2/%s" % (self.registry, api)
response = get(url, auth=(self.user, self.password),
headers={"Accept": 'application/vnd.docker.distribution.manifest.v2+json'})
if response.status_code == 401:
challenge = response.headers['Www-Authenticate']
if challenge.startswith("Bearer "):
challenge = challenge[7:]
opts = urllib2.parse_keqv_list(urllib2.parse_http_list(challenge))
authresp = get("{realm}?service={service}&scope={scope}".format(**opts), auth=(self.user, self.password))
if authresp.ok:
token = authresp.json()['token']
response = get(url, headers={'Authorization': 'Bearer %s' % token})
else:
raise TaskError("problem authenticating with docker registry: [%s] %s" % (authresp.status_code,
authresp.content))
return response
评论列表
文章目录