Skip to content

Commit

Permalink
fix: Type error
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Jul 15, 2024
1 parent fd1387e commit 0515970
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/ai/backend/manager/container_registry/harbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ async def _scan_image(
match image_info["manifest_media_type"]:
case self.MEDIA_TYPE_OCI_INDEX:
await self._process_oci_index(
tg, sess, rqst_args, image, image_info
tg, sess, rqst_args, image, tag, image_info
)
case self.MEDIA_TYPE_DOCKER_MANIFEST_LIST:
await self._process_docker_v2_multiplatform_image(
tg, sess, rqst_args, image, image_info
tg, sess, rqst_args, image, tag, image_info
)
case self.MEDIA_TYPE_DOCKER_MANIFEST:
await self._process_docker_v2_image(
tg, sess, rqst_args, image, image_info
tg, sess, rqst_args, image, tag, image_info
)
case _ as media_type:
raise RuntimeError(
Expand Down Expand Up @@ -292,15 +292,19 @@ async def _scan_tag(
resp.raise_for_status()
resp_json = await resp.json()
async with aiotools.TaskGroup() as tg:
tag = resp_json["tags"][0]["name"]

match resp_json["manifest_media_type"]:
case self.MEDIA_TYPE_OCI_INDEX:
await self._process_oci_index(tg, sess, rqst_args, image, resp_json)
await self._process_oci_index(tg, sess, rqst_args, image, tag, resp_json)
case self.MEDIA_TYPE_DOCKER_MANIFEST_LIST:
await self._process_docker_v2_multiplatform_image(
tg, sess, rqst_args, image, resp_json
tg, sess, rqst_args, image, tag, resp_json
)
case self.MEDIA_TYPE_DOCKER_MANIFEST:
await self._process_docker_v2_image(tg, sess, rqst_args, image, resp_json)
await self._process_docker_v2_image(
tg, sess, rqst_args, image, tag, resp_json
)
case _ as media_type:
raise RuntimeError(f"Unsupported artifact media-type: {media_type}")

Expand All @@ -310,14 +314,14 @@ async def _process_oci_index(
sess: aiohttp.ClientSession,
_rqst_args: Mapping[str, Any],
image: str,
tag: str,
image_info: Mapping[str, Any],
) -> None:
rqst_args = dict(_rqst_args)
if not rqst_args.get("headers"):
rqst_args["headers"] = {}
rqst_args["headers"].update({"Accept": "application/vnd.oci.image.manifest.v1+json"})
digests: list[tuple[str, str]] = []
tag_name = image_info["tags"][0]["name"]
for reference in image_info["references"]:
if (
reference["platform"]["os"] == "unknown"
Expand All @@ -335,7 +339,7 @@ async def _process_oci_index(
rqst_args,
image,
digest=digest,
tag=tag_name,
tag=tag,
architecture=architecture,
)
)
Expand All @@ -346,6 +350,7 @@ async def _process_docker_v2_multiplatform_image(
sess: aiohttp.ClientSession,
_rqst_args: Mapping[str, Any],
image: str,
tag: str,
image_info: Mapping[str, Any],
) -> None:
rqst_args = dict(_rqst_args)
Expand All @@ -355,7 +360,6 @@ async def _process_docker_v2_multiplatform_image(
"Accept": "application/vnd.docker.distribution.manifest.v2+json"
})
digests: list[tuple[str, str]] = []
tag_name = image_info["tags"][0]["name"]
for reference in image_info["references"]:
if (
reference["platform"]["os"] == "unknown"
Expand All @@ -373,7 +377,7 @@ async def _process_docker_v2_multiplatform_image(
rqst_args,
image,
digest=digest,
tag=tag_name,
tag=tag,
architecture=architecture,
)
)
Expand All @@ -384,6 +388,7 @@ async def _process_docker_v2_image(
sess: aiohttp.ClientSession,
_rqst_args: Mapping[str, Any],
image: str,
tag: str,
image_info: Mapping[str, Any],
) -> None:
rqst_args = dict(_rqst_args)
Expand All @@ -394,14 +399,13 @@ async def _process_docker_v2_image(
})
if (reporter := progress_reporter.get()) is not None:
reporter.total_progress += 1
tag_name = image_info["tags"][0]["name"]
async with aiotools.TaskGroup() as tg:
tg.create_task(
self._harbor_scan_tag_single_arch(
sess,
rqst_args,
image,
tag=tag_name,
tag,
)
)

Expand Down

0 comments on commit 0515970

Please sign in to comment.