Image untagger

class pubtools._quay.image_untagger.ImageUntagger(references: List[str], quay_api_token: str, remove_last: bool = False, quay_user: Optional[str] = None, quay_password: Optional[str] = None, host: Optional[str] = None)[source]

Class containing logic for untagging images and deciding if they should be untagged.

__init__(references: List[str], quay_api_token: str, remove_last: bool = False, quay_user: Optional[str] = None, quay_password: Optional[str] = None, host: Optional[str] = None) None[source]

Initialize.

Args:
references ([str]):

List of image references to untag.

quay_api_token (str):

OAuth token for authentication of Quay REST API.

remove_last (bool):

Whether to remove a tag when it’s the last reference of an image (in that repo).

quay_user (str):

Quay username for Docker HTTP API.

quay_password (str):

Quay password for Docker HTTP API.

host (str):

Custom Quay hostname (if required).

set_quay_client(quay_client: QuayClient) None[source]

Set client instance to be used for the HTTP API operations.

Args:
quay_client (QuayClient):

Instance of QuayClient.

get_repository_tags_mapping() Dict[str, List[str]][source]

Get a mapping of which tags would be removed from given repos based on provided refs.

Returns ({str: [str]}):

Mapping of repository->tags.

construct_tag_digest_mappings(repository: str) Tuple[Dict[str, List[str]], Dict[str, List[str]]][source]

Create a mappings of tags->digests as well as digests->tags.

Tags->digests mapping answers the question “Which digests does a given tag reference?”. Digests->tags mapping answers the question “Which tags reference a given digest?”. Tag may reference one digest (if image manifest), or multiple (if manifest list).

Args:
repository (str):

Quay repository.

Returns (({str: [str]}), ({str: [str]})):

Tuple of dictionaries mapping tags->digests and digests->tags.

get_lost_digests(tags: List[str], tag_digest_mapping: Dict[str, List[str]], digest_tag_mapping: Dict[str, List[str]]) List[str][source]

Calculate a list of digests that would be lost if the provided tags were removed.

Args:
tags ([str]):

List of tags that would be removed from a repo.

tag_digest_mapping ({str: [str]}):

Mapping of which digests are referenced by a given tag.

digest_tag_mapping ({str: [str]}):

Mapping of which tags reference a given digest.

Returns ([str]):

Digests that would be lost if given tags were removed.

untag_images() List[str][source]

Determine if the specified tags may be removed and remove them.

Returns ([str]):

List of image references lost by the untagging.