From 79a3612e8c9ae5511dca2ee90733c3bb2779150a Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 2 Nov 2023 10:22:12 -0700 Subject: [PATCH] WIP --- .gitignore | 3 +++ src/rsp_reaper/storage/gar.py | 30 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index ce08ca8..df49be7 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,6 @@ dmypy.json # VSCode .vscode/ + +# AJT manual testing +harnesses/ diff --git a/src/rsp_reaper/storage/gar.py b/src/rsp_reaper/storage/gar.py index d7eb268..1626031 100644 --- a/src/rsp_reaper/storage/gar.py +++ b/src/rsp_reaper/storage/gar.py @@ -1,6 +1,5 @@ import datetime import json -from dataclasses import dataclass from pathlib import Path from typing import Any @@ -16,12 +15,6 @@ from ..models.registry_category import RegistryCategory -@dataclass -class GARImage: - name: str - image: Image - - class GARClient: """Client for Google Artifact Registry. @@ -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( @@ -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(