def _content( self, suffix, accepted_mimes=None, cache=True ): """Fetches content of the resources from registry by http calls.""" if isinstance(self._name, docker_name.Repository): suffix = '{repository}/{suffix}'.format( repository=self._name.repository, suffix=suffix) if suffix in self._response: return self._response[suffix] _, content = self._transport.Request( '{scheme}://{registry}/v2/{suffix}'.format( scheme=docker_http.Scheme(self._name.registry), registry=self._name.registry, suffix=suffix), accepted_codes=[httplib.OK], accepted_mimes=accepted_mimes) if cache: self._response[suffix] = content return content
def Delete(name, creds, transport): """Delete a tag or digest. Args: name: a docker_name.{Tag,Digest} to be deleted. creds: the docker_creds to use for deletion. transport: the transport to use to contact the registry. """ docker_transport = docker_http.Transport(name, creds, transport, docker_http.DELETE) if isinstance(name, docker_name.Tag): entity = name.tag else: assert isinstance(name, docker_name.Digest) entity = name.digest resp, unused_content = docker_transport.Request( '{scheme}://{registry}/v2/{repository}/manifests/{entity}'.format( scheme=docker_http.Scheme(name.registry), registry=name.registry, repository=name.repository, entity=entity), method='DELETE', accepted_codes=[httplib.OK])
def _content(self, suffix, accepted_mimes=None): """Fetches content of the resources from registry by http calls.""" if suffix not in self._response: _, self._response[suffix] = self._transport.Request( '{scheme}://{registry}/v2/{repository}/{suffix}'.format( scheme=docker_http.Scheme(self._name.registry), registry=self._name.registry, repository=self._name.repository, suffix=suffix), accepted_codes=[httplib.OK], accepted_mimes=accepted_mimes) return self._response[suffix]
def blob_size(self, digest): """The byte size of the raw blob.""" suffix = 'blobs/' + digest if isinstance(self._name, docker_name.Repository): suffix = '{repository}/{suffix}'.format( repository=self._name.repository, suffix=suffix) resp, unused_content = self._transport.Request( '{scheme}://{registry}/v2/{suffix}'.format( scheme=docker_http.Scheme(self._name.registry), registry=self._name.registry, suffix=suffix), method='HEAD', accepted_codes=[six.moves.http_client.OK]) return int(resp['content-length'])
def Delete(name, creds, transport): """Delete a tag or digest. Args: name: a tag or digest to be deleted. creds: the creds to use for deletion. transport: the transport to use to contact the registry. """ docker_transport = docker_http.Transport(name, creds, transport, docker_http.DELETE) resp, unused_content = docker_transport.Request( '{scheme}://{registry}/v2/{repository}/manifests/{entity}'.format( scheme=docker_http.Scheme(name.registry), registry=name.registry, repository=name.repository, entity=_tag_or_digest(name)), method='DELETE', accepted_codes=[httplib.OK])
def catalog(self, page_size=100): # TODO(user): Handle docker_name.Repository for /v2/<name>/_catalog if isinstance(self._name, docker_name.Repository): raise ValueError('Expected docker_name.Registry for "name"') url = '{scheme}://{registry}/v2/_catalog?n={page_size}'.format( scheme=docker_http.Scheme(self._name.registry), registry=self._name.registry, page_size=page_size) for _, content in self._transport.PaginatedRequest( url, accepted_codes=[httplib.OK]): wrapper_object = json.loads(content) if 'repositories' not in wrapper_object: raise docker_http.BadStateException( 'Malformed JSON response: %s' % content) for repo in wrapper_object['repositories']: yield repo
def _scheme_and_host(self): return '{scheme}://{registry}'.format(scheme=docker_http.Scheme( self._name.registry), registry=self._name.registry)
def _base_url(self): return '{scheme}://{registry}/v2/{repository}'.format( scheme=docker_http.Scheme(self._name.registry), registry=self._name.registry, repository=self._name.repository)