forked from quarkusio/quarkus-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatequay.py
45 lines (33 loc) · 1.57 KB
/
updatequay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## Update description by parsing Cekit yaml and extract io.k8s.description
## and updating repo via quay.io api.
## Require application token from an organization that have write access.
import requests
import yaml
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('files', metavar="Files", type=str, nargs="+", help="File to extract metadata from.")
parser.add_argument('--token', metavar="Token", type=str, required=True, help="quay.io token that has write access.")
args = parser.parse_args()
for f in args.files:
with open(f, 'r') as stream:
try:
data = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print("Error parsing: " + f)
if data:
name = data['name']
if name.startswith("quay.io/"):
name = name[len("quay.io/"):]
repoapiurl = 'https://quay.io/api/v1/repository/' + name
reallabels = data['labels']
labels = {}
for l in reallabels:
labels[l["name"]] = l["value"]
description = labels["io.k8s.description"] + "\n\n\n[Source](https://github.com/quarkusio/quarkus-images)"
print("Setting '{0}' description to '{1}'".format(name, description))
r = requests.put(repoapiurl,
headers={'Content-Type': 'application/json', 'Authorization': 'Bearer ' + args.token},
json={"description":description})
print(r.text)
else:
print("Skipping " + f + " as not referencing quay.io")