-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9cb945
commit aff7b9a
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import logging | ||
import urllib.parse | ||
from typing import AsyncIterator | ||
|
||
import aiohttp | ||
|
||
from ai.backend.common.logging import BraceStyleAdapter | ||
|
||
from .base import ( | ||
BaseContainerRegistry, | ||
) | ||
|
||
log = BraceStyleAdapter(logging.getLogger(__spec__.name)) # type: ignore[name-defined] | ||
|
||
|
||
class GitLabRegistry_v2(BaseContainerRegistry): | ||
async def fetch_repositories(self, sess: aiohttp.ClientSession) -> AsyncIterator[str]: | ||
access_token, gitlab_project = ( | ||
self.registry_info["password"], | ||
self.registry_info["gitlab_project"], | ||
) | ||
encoded_project_id = urllib.parse.quote(gitlab_project, safe="") | ||
|
||
base_url = f"https://gitlab.com/api/v4/projects/{encoded_project_id}/registry/repositories" | ||
|
||
headers = { | ||
"Accept": "application/json", | ||
"PRIVATE-TOKEN": access_token, | ||
} | ||
page = 1 | ||
|
||
while True: | ||
async with sess.get( | ||
base_url, | ||
headers=headers, | ||
params={"per_page": 30, "page": page, "membership": "true"}, | ||
) as response: | ||
if response.status == 200: | ||
data = await response.json() | ||
|
||
for repo in data: | ||
yield repo["path"] | ||
if "next" in response.headers.get("Link", ""): | ||
page += 1 | ||
else: | ||
break | ||
else: | ||
raise RuntimeError( | ||
f"Failed to fetch repositories! {response.status} error occurred." | ||
) |