def __init__( self, name, creds, transport, mount=None, threads=1): """Constructor. If multiple threads are used, the caller *must* ensure that the provided transport is thread-safe, as well as the image that is being uploaded. It is notable that tarfile and httplib2.Http in Python are NOT threadsafe. Args: name: the fully-qualified name of the tag to push creds: credential provider for authorizing requests transport: the http transport to use for sending requests mount: list of repos from which to mount blobs. threads: the number of threads to use for uploads. Raises: ValueError: an incorrectly typed argument was supplied. """ self._name = name self._transport = docker_http.Transport( name, creds, transport, docker_http.PUSH) self._mount = mount self._threads = threads
def __enter__(self): # Create a v2 transport to use for making authenticated requests. self._transport = docker_http.Transport(self._name, self._creds, self._original_transport, docker_http.PULL) return self
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 __init__(self, name, creds, transport, mount=None, threads=1): """Constructor. If multiple threads are used, the caller *must* ensure that the provided transport is thread-safe, as well as the image that is being uploaded. It is notable that tarfile and httplib2.Http in Python are NOT threadsafe. Args: name: docker_name.Tag, the fully-qualified name of the tag to push creds: docker_creds._CredentialProvider, provider for authorizing requests transport: httplib2.Http, the http transport to use for sending requests mount: list of docker_name.Repository, repos from which to mount blobs. threads: the number of threads to use for uploads. Raises: ValueError: an incorrectly typed argument was supplied. """ # TODO(user): Add support for pushing by manifest if not isinstance(name, docker_name.Tag): raise ValueError('Expected docker_name.Tag for "name"') if mount and not isinstance(mount, list): raise ValueError( 'Expected list of docker_name.Repository for "mount"') self._name = name self._transport = docker_http.Transport(name, creds, transport, docker_http.PUSH) self._mount = mount self._threads = threads
def _mk_transport( image_name: str, credentials_lookup: typing.Callable[[image_reference, oa.Privileges, bool], oa.OciConfig], action: str = docker_http.PULL, privileges: oa.Privileges = oa.Privileges.READONLY, ): if isinstance(image_name, str): image_name = ou.normalise_image_reference(image_name) credentials = _mk_credentials( image_reference=str(image_name), credentials_lookup=credentials_lookup, privileges=privileges, ) if isinstance(image_name, str): image_name = docker_name.from_string(name=image_name) transport_pool = _mk_transport_pool(size=1) transport = docker_http.Transport( name=image_name, creds=credentials, transport=transport_pool, action=docker_http.PULL, ) return transport
def __init__(self, name, creds, transport): """Constructor. Args: name: docker_name.Tag, the fully-qualified name of the tag to push creds: docker_creds._CredentialProvider, provider for authorizing requests transport: httplib2.Http, the http transport to use for sending requests Raises: ValueError: an incorrectly typed argument was supplied. """ # TODO(user): Add support for pushing by manifest if not isinstance(name, docker_name.Tag): raise ValueError('Expected docker_name.Tag for "name"') self._name = name self._transport = docker_http.Transport( name, creds, transport, docker_http.PUSH)
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])