Quay Client

Class used for performing Docker HTTP API queries on Quay. Only necessary queries have been implemented, though more may be added, as required. Standard authentication procedure is also handled by this class.

Authentication details can be found at https://docs.docker.com/registry/spec/auth/token/

Full Docker HTTP API reference can be found at https://docs.docker.com/registry/spec/api/

class pubtools._quay.quay_client.QuayClient(username: Optional[str], password: Optional[str], host: Optional[str] = None)[source]

Class for performing Docker HTTP API operations with the Quay registry.

__init__(username: Optional[str], password: Optional[str], host: Optional[str] = None) None[source]

Initialize.

Args:
username (str):

Quay username.

password (str):

Quay password.

host (str):

Quay registry URL.

get_manifest(image: str, raw: bool = False, media_type: Optional[str] = None, return_headers: bool = False) Union[ManifestList, Manifest, str, Tuple[str, Mapping[str, str]]][source]

Get manifest of given media type.

Args:
image (str):

Image for which to get the manifest list.

raw (bool):

Whether to return the manifest as raw JSON.

manifest_list (bool):

Whether to only return a manifest list and raise an exception otherwise.

media_type (str):

Can be application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.v1+json, application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json or None indicating which manifest type is requested. If it’s None, manifest list is prefered, but if v2s2 is returned instead, v2s2 is returned as final result. If neither is found, same order is attempted with OCI type images.

Returns (dict|str):

Image manifest

Raises:
ManifestTypeError:

When the image doesn’t return the requested manifest type.

ValueError:

If Manifest list and V2S1 manifest are requested at the same time.

get_manifest_digest(image: str, media_type: Optional[str] = None) str[source]

Get manifest of the specified image and calculate its digest by hashing it.

Args:
image (str):

Image address for which to calculate the digest.

media_type (str):

Type of manifest can be application/vnd.docker.distribution.manifest.v2+json or application/vnd.docker.distribution.manifest.v1+json

Returns (str):

Manifest digest of the image.

upload_manifest(manifest: Union[ManifestList, str], image: str, raw: bool = False) None[source]

Upload manifest to a specified image.

All manifest types are supported (manifest, manifest list).

Args:
manifest (dict):

Manifest to be uploaded.

image (str):

Image address to upload the manifest to.

raw (bool):

Whether the given manifest is a string (raw) or a Python dictionary

get_repository_tags(repository: str, raw: bool = False) Union[str, Dict[str, List[str]]][source]

Get tags of a provided repository.

Args:
repository (str):

Repository whose tags should be gathered (expected format namespce/repo).

raw (bool):

Whether the given manifest is a string (raw) or a Python dictionary

Returns (list):

Tags which the repository contains.

_request_quay(method: str, endpoint: str, kwargs: Dict[Any, Any] = {}) Response[source]

Perform a Docker HTTP API request on Quay registry. Handle authentication.

Args:
method (str):

REST API method of the request (GET, POST, PUT, DELETE).

endpoint (str):

Endpoint of the request.

kwargs (dict):

Optional arguments to add to the Request object.

Returns (Response):

Request library’s Response object.

Raises:

HTTPError: When the request returned an error status.

_authenticate_quay(headers: Union[Dict[Any, Any], Mapping[str, Any]]) None[source]

Attempt to perform an authentication with registry’s authentication server.

Once authentication is complete, add the token to the Session object. Specifics can be found at https://docs.docker.com/registry/spec/auth/token/

Args:
headers (dict):

Headers of the 401 response received from the registry.

Raises:
RegistryAuthError:

When there’s an issue with the authentication procedure.

_parse_and_validate_image_url(image: str) Tuple[str, str][source]

Extract image repository + reference from an image and validate its data.

Args:
image (str):

A quay.io image.

Returns (str, str):

Tuple containing image repository (without base URL) and reference.

Raises:
ValueError:

If image doesn’t contain the expected data.