构建使用基础镜像
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

36 lines
1.3 KiB

3 years ago
import requests
from urllib import parse
session = requests.Session()
HEADERS = {'Content-Type': 'application/x-www-form-urlencoded'}
def get_session():
payload = {"principal": 'admin', "password": 'Harbor12345'}
data = parse.urlencode(payload)
r = session.post("https://repository.anxinyun.cn/login", headers=HEADERS, data=data)
print(r.status_code)
def get_all_project():
url = "https://repository.anxinyun.cn/api/projects?page=1&page_size=100"
rs = session.get(url)
if rs.status_code == 200:
projects = dict()
for p in rs.json():
projects[p['name']] = p['project_id']
return projects
def get_image_latest_tag(project, image):
url = "https://repository.anxinyun.cn/api/repositories/{}/{}/tags?detail=1".format(project, image)
r = session.get(url)
if r.status_code == 200:
tags = list(map(lambda t: {'created': t['created'], 'tag': t['name']}, r.json()))
tags.sort(key=lambda x: x['created'], reverse=True)
return tags[0]['tag'] if len(tags) == 1 else tags[0]['tag'] if tags[0]['tag'] != 'latest' else tags[1]['tag']
# if len(tags) >= 2:
# return tags[0]['tag'] if tags[0]['tag'] != 'latest' else tags[1]['tag']
# else:
# return tags[0]['tag']