harbor是基于Bearer的认证,我们只需要两步即可获取harbor的镜像列表
首先获取token
#!/usr/bin/python33 #coding:utf-8 import requests import json r = requests.get("http://192.168.31.180/service/token?account=admin&service=harbor-registry&scope=registry:catalog:*", auth=("admin","admin12345")) res = json.loads(r.text) print(res)
上述可以打印出token
获得了token以后我们可以在请求头中添加token来验证身份,同时harbor是基于bearer的认证,需要在authorization值中拼接bearer字符串,代码如下
headers = { "authorization": "bearer "+res["token"] } r2 = requests.get("http://192.168.31.180/v2/_catalog", headers=headers) #print(r2.text) res2 = json.loads(r2.text) images_list = res2["repositories"] print(type(images_list)) for p in images_list: print(p)
最后打印出结果
获取其它信息的URL后面再收集吧