-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (34 loc) · 1.42 KB
/
main.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
46
47
48
49
50
import sys
import requests
import yaml
def read_Functionio() -> dict:
"""Read the FunctionIO from stdin."""
return yaml.load(sys.stdin.read(), yaml.Loader)
def write_Functionio(Functionio: dict):
"""Write the FunctionIO to stdout and exit."""
sys.stdout.write(yaml.dump(Functionio))
sys.exit(0)
def result_warning(Functionio: dict, message: str):
"""Add a warning result to the supplied FunctionIO."""
if "results" not in Functionio:
Functionio["results"] = []
Functionio["results"].append({"severity": "Warning", "message": message})
def main():
"""Annotate all desired composed resources with a quote from quotable.io"""
try:
Functionio = read_Functionio()
except yaml.parser.ParserError as err:
sys.stdout.write("cannot parse FunctionIO: {}\n".format(err))
sys.exit(1)
composite = Functionio["desired"]["composite"]["resource"]
if "metadata" not in composite:
print("Added metadata")
composite["metadata"] = {}
if "annotations" not in composite["metadata"]:
print("Added annotations")
composite["metadata"]["annotations"] = {}
if not "appcat.io/effectiveVersion" in composite["metadata"]["annotations"]:
composite["metadata"]["annotations"]["appcat.io/effectiveVersion"] = composite["spec"]["parameters"]["service"]["version"]
write_Functionio(Functionio)
if __name__ == "__main__":
main()