mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
parent
6f7633a93c
commit
68fcfe3924
2 changed files with 30 additions and 5 deletions
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
from typing import Dict, List, NamedTuple, Optional, Tuple
|
from typing import Dict, List, NamedTuple, Optional, Tuple
|
||||||
from urllib.request import parse_http_list
|
from urllib.request import parse_http_list
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
from nvchecker.api import session, HTTPError
|
from nvchecker.api import session, HTTPError
|
||||||
|
|
||||||
|
@ -65,11 +66,29 @@ async def get_container_tags(info: Tuple[str, str, AuthInfo]) -> List[str]:
|
||||||
res = await session.get(auth_info.realm, params=auth_params)
|
res = await session.get(auth_info.realm, params=auth_params)
|
||||||
token = res.json()['token']
|
token = res.json()['token']
|
||||||
|
|
||||||
res = await session.get(f'https://{registry_host}/v2/{image_path}/tags/list', headers={
|
tags = []
|
||||||
'Authorization': f'Bearer {token}',
|
url = f'https://{registry_host}/v2/{image_path}/tags/list'
|
||||||
'Accept': 'application/json',
|
|
||||||
})
|
while True:
|
||||||
return res.json()['tags']
|
res = await session.get(url, headers={
|
||||||
|
'Authorization': f'Bearer {token}',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
})
|
||||||
|
tags += res.json()['tags']
|
||||||
|
link = res.headers.get('Link')
|
||||||
|
if link is None:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
url = urljoin(url, parse_next_link(link))
|
||||||
|
|
||||||
|
return tags
|
||||||
|
|
||||||
|
def parse_next_link(value: str) -> str:
|
||||||
|
ending = '>; rel="next"'
|
||||||
|
if value.endswith(ending):
|
||||||
|
return value[1:-len(ending)]
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
|
||||||
async def get_version(name, conf, *, cache, **kwargs):
|
async def get_version(name, conf, *, cache, **kwargs):
|
||||||
image_path = conf.get('container', name)
|
image_path = conf.get('container', name)
|
||||||
|
|
|
@ -10,3 +10,9 @@ async def test_container(get_version):
|
||||||
"container": "library/hello-world",
|
"container": "library/hello-world",
|
||||||
"include_regex": "linux",
|
"include_regex": "linux",
|
||||||
}) == "linux"
|
}) == "linux"
|
||||||
|
|
||||||
|
async def test_container_paging(get_version):
|
||||||
|
assert await get_version("prometheus-operator", {
|
||||||
|
"source": "container",
|
||||||
|
"container": "prometheus-operator/prometheus-operator",
|
||||||
|
}) == "v0.48.1"
|
||||||
|
|
Loading…
Add table
Reference in a new issue