mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-02 14:31:01 +02:00
Docker hub cleanup util
This commit is contained in:
parent
fe4d55325c
commit
b28bec25e1
1 changed files with 14 additions and 3 deletions
|
|
@ -87,6 +87,8 @@ def get_repos(namespace, token):
|
||||||
url = f"{HUB_API}/repositories/{namespace}/?page_size=100"
|
url = f"{HUB_API}/repositories/{namespace}/?page_size=100"
|
||||||
while url:
|
while url:
|
||||||
resp = requests.get(url, headers={"Authorization": f"JWT {token}"})
|
resp = requests.get(url, headers={"Authorization": f"JWT {token}"})
|
||||||
|
if resp.status_code == 404:
|
||||||
|
break
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
repos.extend(data["results"])
|
repos.extend(data["results"])
|
||||||
|
|
@ -100,6 +102,8 @@ def get_tags(namespace, repo, token):
|
||||||
url = f"{HUB_API}/repositories/{namespace}/{repo}/tags/?page_size=100"
|
url = f"{HUB_API}/repositories/{namespace}/{repo}/tags/?page_size=100"
|
||||||
while url:
|
while url:
|
||||||
resp = requests.get(url, headers={"Authorization": f"JWT {token}"})
|
resp = requests.get(url, headers={"Authorization": f"JWT {token}"})
|
||||||
|
if resp.status_code == 404:
|
||||||
|
break
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
tags.extend(data["results"])
|
tags.extend(data["results"])
|
||||||
|
|
@ -140,11 +144,12 @@ def main():
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--token",
|
"--token",
|
||||||
help="Docker Hub PAT (or set DOCKER_HUB_TOKEN env var)",
|
help="Docker Hub PAT (or set DOCKER_HUB_TOKEN env var). "
|
||||||
|
"Requires --username to exchange for a JWT.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--username",
|
"--username",
|
||||||
help="Docker Hub username (alternative to PAT)",
|
help="Docker Hub username (required with --token, or with --password)",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--password",
|
"--password",
|
||||||
|
|
@ -171,7 +176,13 @@ def main():
|
||||||
|
|
||||||
token = args.token or os.environ.get("DOCKER_HUB_TOKEN")
|
token = args.token or os.environ.get("DOCKER_HUB_TOKEN")
|
||||||
if token:
|
if token:
|
||||||
auth_token = token
|
if not args.username:
|
||||||
|
print(
|
||||||
|
"Error: --username is required when using --token / DOCKER_HUB_TOKEN",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
auth_token = authenticate(args.username, token)
|
||||||
elif args.username and args.password:
|
elif args.username and args.password:
|
||||||
auth_token = authenticate(args.username, args.password)
|
auth_token = authenticate(args.username, args.password)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue