Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
athornton committed Nov 2, 2023
1 parent 463a9fe commit 79a3612
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@ dmypy.json

# VSCode
.vscode/

# AJT manual testing
harnesses/
30 changes: 16 additions & 14 deletions src/rsp_reaper/storage/gar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import json
from dataclasses import dataclass
from pathlib import Path
from typing import Any

Expand All @@ -16,12 +15,6 @@
from ..models.registry_category import RegistryCategory


@dataclass
class GARImage:
name: str
image: Image


class GARClient:
"""Client for Google Artifact Registry.
Expand Down Expand Up @@ -49,25 +42,32 @@ def __init__(

def scan_repo(self) -> None:
images: list[DockerImage] = []
request = ListDockerImagesRequest(parent=self._parent)
calls = 1
page_size = 100
request = ListDockerImagesRequest(
parent=self._parent, page_size=page_size
)
count = 0
while True:
self._logger.debug(f"Requesting {self._path}: #{calls}")
self._logger.debug(
f"Requesting {self._path}: images "
f"{count*page_size + 1}-{(count+1) * page_size}"
)
resp = self._client.list_docker_images(request=request)
images.extend(list(resp.docker_images))
if not resp.next_page_token:
break
request = ListDockerImagesRequest(
parent=self._parent, page_token=resp.next_page_token
parent=self._parent,
page_token=resp.next_page_token,
page_size=page_size,
)
calls += 1
count += 1
self._logger.debug(f"Found {len(images)} images")
self._images = self._gar_to_images(images)

def _gar_to_images(self, images: list[DockerImage]) -> list[Image]:
ret: dict[str, Image] = {}
for img in images:
self._logger.debug(f"GAR Image: {img}")
ut = img.update_time
micros = int(ut.nanosecond / 1000)
dt = datetime.datetime(
Expand Down Expand Up @@ -130,7 +130,9 @@ def delete_untagged(self) -> None:
count = 0
for u in untagged:
digest = u.digest
request = DeleteVersionRequest(name=self._image_to_name(u))
request = DeleteVersionRequest(
name=self._image_to_name(u), force=True
)
self._logger.debug(f"Deletion request: {request}")
operation = self._client.delete_version(request=request)
self._logger.debug(
Expand Down

0 comments on commit 79a3612

Please sign in to comment.