Commit 99bed9fc authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

fix(srm): normalize adapter-backed federation flows

parent fb67c924
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -48,6 +48,10 @@ def _safe_http_json_response(response):
    if isinstance(response, (list, dict)):
        return response, 200

    # Adapter returned normalized tuple
    if isinstance(response, tuple) and len(response) == 2:
        return response

    # Adapter returned nothing
    if response is None:
        return {"error": "Adapter returned no response"}, 502
+18 −12
Original line number Diff line number Diff line
@@ -52,15 +52,18 @@ def _build_app_repo_from_artefact(artefact_data):
    repo_location = _repo_credentials(artefact_data.get("artefactRepoLocation"))
    repo_url = repo_location.get("repoURL")
    image_path = repo_url

    if repo_url and artefact_data.get("artefactName") and artefact_data.get("artefactVersionInfo"):
    artefact_name = artefact_data.get("artefactName")
    version = artefact_data.get("artefactVersionInfo")
        if repo_url.endswith("/"):
            image_path = f"{repo_url}{artefact_data.get('artefactName')}:{version}"
        elif "/" in repo_url and not repo_url.endswith(f":{version}"):
            image_path = f"{repo_url.rstrip('/')}/{artefact_data.get('artefactName')}:{version}"
        else:
            image_path = f"{repo_url.rstrip('/')}/{artefact_data.get('artefactName')}:{version}"

    if repo_url and version:
        if repo_url.endswith(f":{version}"):
            image_path = repo_url
        elif repo_url.endswith(f"/{artefact_name}"):
            image_path = f"{repo_url}:{version}"
        elif artefact_name:
            image_path = f"{repo_url.rstrip('/')}/{artefact_name}:{version}"
    elif artefact_name and version:
        image_path = f"{artefact_name}:{version}"

    return {
        "imagePath": image_path,
@@ -102,8 +105,8 @@ def _build_manifest_from_gsma_onboarding(request_data):
    if artefact_id:
        get_artefact_method = _call_first_available(
            edgecloud_adapter,
            "get_artefact",
            "get_artefact_gsma",
            "get_artefact",
        )
        artefact_response = _normalize_adapter_response(get_artefact_method(artefact_id))
        if isinstance(artefact_response, tuple):
@@ -209,6 +212,9 @@ def _extract_deployed_app(response):
    normalized = _normalize_adapter_response(response)
    if isinstance(normalized, tuple):
        data, status = normalized
        if isinstance(data, dict) and data.get("edgeCloudZoneId") is None and data.get("zoneId") is not None:
            data = dict(data)
            data["edgeCloudZoneId"] = data.get("zoneId")
        if isinstance(data, dict) and "appInstance" in data:
            return data["appInstance"], status
        return data, status
@@ -260,8 +266,8 @@ def create_artefact():
        return {"error": "Wrong request schema"}, 400
    create_artefact_method = _call_first_available(
        edgecloud_adapter,
        "create_artefact",
        "create_artefact_gsma",
        "create_artefact",
    )
    response = create_artefact_method(connexion.request.get_json())
    return _normalize_adapter_response(response)
@@ -355,7 +361,7 @@ def get_deployed_app(app_id: str, app_instance_id: str, zone_id: str):
        if data.get("appId") != app_id or data.get("edgeCloudZoneId") != zone_id:
            return {"error": "App instance not found"}, 404
        return {
            "appInstanceState": data.get("appInstanceState"),
            "appInstanceState": data.get("appInstanceState") or data.get("status"),
            "accesspointInfo": data.get("accesspointInfo", []),
        }, status
    return normalized