Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
* Address review comment by replacing variable name image to tag.
* Remove regex compilation flag to avoid confusion. Previous regex match
  did not use it.
* Remove unused import.

Signed-off-by: Chenxiong Qi <[email protected]>
  • Loading branch information
tkdchen committed Jan 10, 2024
1 parent 4243acc commit 6a49cf6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions config/registry_image_pruner/image_pruner/prune_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from collections.abc import Iterator
from http.client import HTTPResponse
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List
from urllib.parse import urlencode
from urllib.request import Request, urlopen

Expand Down Expand Up @@ -48,18 +48,18 @@ def delete_image_repo(quay_token: str, namespace: str, name: str, tag: str) -> N

def remove_images(images: Dict[str, Any], quay_token: str, namespace: str, name: str, dry_run: bool = False) -> None:
image_digests = [image["manifest_digest"] for image in images.values()]
image_regex = re.compile(r"^sha256-([0-9a-f]+)(\.sbom|\.att)$", re.IGNORECASE)
for image in images:
image_regex = re.compile(r"^sha256-([0-9a-f]+)(\.sbom|\.att)$")
for tag in images:
# attestation or sbom image
if (match := image_regex.match(image)) is not None:
if (match := image_regex.match(tag)) is not None:
if f"sha256:{match.group(1)}" not in image_digests:
if dry_run:
LOGGER.info("Image %s from %s/%s should be removed", image, namespace, name)
LOGGER.info("Image %s from %s/%s should be removed", tag, namespace, name)
else:
LOGGER.info("Removing image %s from %s/%s", image, namespace, name)
delete_image_repo(quay_token, namespace, name, image)
LOGGER.info("Removing image %s from %s/%s", tag, namespace, name)
delete_image_repo(quay_token, namespace, name, tag)
else:
LOGGER.debug("%s is not an image with suffix .att or .sbom", image)
LOGGER.debug("%s is not an image with suffix .att or .sbom", tag)


def process_repositories(repos: List[ImageRepo], quay_token: str, dry_run: bool = False) -> None:
Expand Down

0 comments on commit 6a49cf6

Please sign in to comment.