docker.py 文件源码

python
阅读 39 收藏 0 点赞 0 评论 0

项目:forge 作者: datawire 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号