def __init__(self, base_url="unix://var/run/docker.sock", version="1.4"): super(Client, self).__init__() self.mount('unix://', unixconn.UnixAdapter(base_url)) self.base_url = base_url self._version = version try: self._cfg = auth.load_config() except Exception: pass
def push(self, repository): registry, repository = auth.resolve_repository_name(repository) if getattr(self, '_cfg', None) is None: self._cfg = auth.load_config() authcfg = auth.resolve_authconfig(self._cfg, registry) u = self._url("/images/{0}/push".format(repository)) if utils.compare_version('1.5', self._version) >= 0: headers = { 'X-Registry-Auth': auth.encode_header(authcfg) } return self._result(self._post_json(u, None, headers=headers)) return self._result(self._post_json(u, authcfg))
def push(self, repository): registry, repository = auth.resolve_repository_name(repository) u = self._url("/images/{0}/push".format(repository)) headers = {} if getattr(self, '_cfg', None) is None: self._cfg = auth.load_config() authcfg = auth.resolve_authconfig(self._cfg, registry) if utils.compare_version('1.5', self._version) >= 0: # do not fail if no atuhentication exists # for this specific registry as we can have an anon push if authcfg: headers['X-Registry-Auth'] = auth.encode_header(authcfg) return self._result(self._post_json(u, None, headers=headers)) return self._result(self._post_json(u, authcfg))
def login(self, username, password=None, email=None): url = self._url("/auth") res = self.get(url) json_ = res.json() if 'username' in json_ and json_['username'] == username: return json_ req_data = { 'username': username, 'password': password if password is not None else json_['password'], 'email': email if email is not None else json_['email'] } res = self._result(self._post_json(url, req_data), True) try: self._cfg = auth.load_config() finally: return res
def login(self, username, password=None, email=None, registry=None): url = self._url("/auth") if registry is None: registry = auth.INDEX_URL if getattr(self, '_cfg', None) is None: self._cfg = auth.load_config() authcfg = auth.resolve_authconfig(self._cfg, registry) if 'username' in authcfg and authcfg['username'] == username: return authcfg req_data = { 'username': username, 'password': password, 'email': email } res = self._result(self._post_json(url, req_data), True) if res['Status'] == 'Login Succeeded': self._cfg['Configs'][registry] = req_data return res
def pull(self, repository, tag=None): registry, repo_name = auth.resolve_repository_name(repository) if repo_name.count(":") == 1: repository, tag = repository.rsplit(":", 1) params = { 'tag': tag, 'fromImage': repository } headers = {} if utils.compare_version('1.5', self._version) >= 0: if getattr(self, '_cfg', None) is None: self._cfg = auth.load_config() authcfg = auth.resolve_authconfig(self._cfg, registry) headers = { 'X-Registry-Auth': auth.encode_header(authcfg) } u = self._url("/images/create") return self._result(self.post(u, params=params, headers=headers))
def pull(self, repository, tag=None): registry, repo_name = auth.resolve_repository_name(repository) if repo_name.count(":") == 1: repository, tag = repository.rsplit(":", 1) params = { 'tag': tag, 'fromImage': repository } headers = {} if utils.compare_version('1.5', self._version) >= 0: if getattr(self, '_cfg', None) is None: self._cfg = auth.load_config() authcfg = auth.resolve_authconfig(self._cfg, registry) # do not fail if no atuhentication exists # for this specific registry as we can have a readonly pull if authcfg: headers['X-Registry-Auth'] = auth.encode_header(authcfg) u = self._url("/images/create") return self._result(self.post(u, params=params, headers=headers))