Skip to content

Commit 59b5630

Browse files
committed
feat: check csars for inputs
1 parent 433fde5 commit 59b5630

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

micado_eec/micado.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from werkzeug.exceptions import BadRequest, NotFound
99

1010
from .handle_micado import HandleMicado
11-
from .utils import base64_to_yaml, is_valid_adt, get_adt_inputs, file_to_json
11+
from .utils import base64_to_yaml, is_valid_adt, get_adt_inputs, get_csar_inputs, file_to_json
1212

1313
r = redis.StrictRedis("redis", decode_responses=True)
1414
if not r.ping():
@@ -131,7 +131,8 @@ def _get_artefact_ports(artefact_data):
131131
"""
132132
free_inputs, free_outputs, parameters = [], [], []
133133
if artefact_data["downloadUrl"].endswith(".csar"):
134-
return [], [], []
134+
params = get_csar_inputs(artefact_data["downloadUrl_content"])
135+
return [], [], params
135136

136137
try:
137138
artefact_content = base64_to_yaml(artefact_data["downloadUrl_content"])

micado_eec/utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import base64
2+
import io
23
import json
4+
import zipfile
35

46
import ruamel.yaml as yaml
57

@@ -59,3 +61,30 @@ def get_adt_inputs(adt):
5961
}
6062
for key, details in adt.get("topology_template", {}).get("inputs", {}).items()
6163
]
64+
65+
def get_csar_inputs(b64_csar):
66+
67+
file_content = base64.b64decode(b64_csar)
68+
69+
file_like_object = io.BytesIO(file_content)
70+
zip_file = zipfile.ZipFile(file_like_object)
71+
72+
params = []
73+
74+
for file in zip_file.namelist():
75+
76+
if not file.endswith('.yaml') or file.startswith('__'):
77+
continue
78+
79+
yaml_file = zip_file.open(file)
80+
adt = yaml.safe_load(yaml_file)
81+
82+
params.extend([
83+
{
84+
"key": key,
85+
"description": details.get("description", "n/a").rstrip(),
86+
}
87+
for key, details in adt.get("topology_template", {}).get("inputs", {}).items()
88+
])
89+
90+
return params

0 commit comments

Comments
 (0)