From 4c1a5a778122c5a7e6bda7be6cbcc6c318d5391b Mon Sep 17 00:00:00 2001 From: gpapathan87 Date: Tue, 22 Jul 2025 15:49:29 +0300 Subject: [PATCH] federation controller changes --- .../federation_manager_controller.py | 49 ++++++------------- .../specification/openapi.yaml | 5 -- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/edge_cloud_management_api/controllers/federation_manager_controller.py b/edge_cloud_management_api/controllers/federation_manager_controller.py index d2fbf4f..8a39a37 100644 --- a/edge_cloud_management_api/controllers/federation_manager_controller.py +++ b/edge_cloud_management_api/controllers/federation_manager_controller.py @@ -1,21 +1,12 @@ from flask import request, jsonify, Response import json +import logging from edge_cloud_management_api.services.federation_services import FederationManagerClientFactory # Factory pattern factory = FederationManagerClientFactory() federation_client = factory.create_federation_client() -def handle_response(status_code, title, detail): - return Response( - json.dumps({ - "title": title, - "detail": detail, - "status": status_code - }), - status=status_code, - content_type="application/problem+json" - ) def create_federation(): @@ -23,44 +14,39 @@ def create_federation(): try: body = request.get_json() result = federation_client.post_partner(body) - if "error" in result: - return handle_response(502, "Federation Error", result["error"]) return jsonify(result), 200 except Exception as e: - return handle_response(400, "Bad Request", str(e)) + logging.error(e.args) + return jsonify(result), 500 def get_federation(federationContextId): """GET /{federationContextId}/partner - Get federation info.""" try: result = federation_client.get_partner(federationContextId) - if "error" in result: - return handle_response(502, "Federation Error", result["error"]) return jsonify(result), 200 except Exception as e: - return handle_response(400, "Bad Request", str(e)) + logging.error(e.args) + return jsonify(result), 500 def delete_federation(federationContextId): """DELETE /{federationContextId}/partner - Delete federation.""" try: result = federation_client.delete_partner(federationContextId) - if "error" in result: - return handle_response(502, "Federation Error", result["error"]) return jsonify(result), 200 except Exception as e: - return handle_response(400, "Bad Request", str(e)) - + logging.error(e.args) + return jsonify(result), 500 def get_federation_context_ids(): """GET /fed-context-id - Fetch federationContextId(s).""" try: result = federation_client.get_federation_context_ids() - if "error" in result: - return handle_response(502, "Federation Error", result["error"]) return jsonify(result), 200 except Exception as e: - return handle_response(400, "Bad Request", str(e)) + logging.error(e.args) + return jsonify(result), 500 def onboard_application_to_partner(federationContextId): @@ -68,31 +54,28 @@ def onboard_application_to_partner(federationContextId): try: body = request.get_json() result = federation_client.onboard_application(federationContextId, body) - if "error" in result: - return handle_response(502, "Onboarding Error", result["error"]) return jsonify(result), 202 except Exception as e: - return handle_response(400, "Bad Request", str(e)) + logging.error(e.args) + return jsonify(result), 500 def get_onboarded_app(federationContextId, appId): """GET /{federationContextId}/application/onboarding/app/{appId}""" try: result = federation_client.get_onboarded_app(federationContextId, appId) - if "error" in result: - return handle_response(result.get("status_code", 502), "Retrieval Error", result["error"]) return jsonify(result), 200 except Exception as e: - return handle_response(500, "Internal Server Error", str(e)) + logging.error(e.args) + return jsonify(result), 500 def delete_onboarded_app(federationContextId, appId): """DELETE /{federationContextId}/application/onboarding/app/{appId}""" try: result = federation_client.delete_onboarded_app(federationContextId, appId) - if "error" in result: - return handle_response(result.get("status_code", 502), "Deletion Error", result["error"]) - return jsonify({"message": f"App {appId} successfully deleted from partner"}), 200 + return jsonify(result), 200 except Exception as e: - return handle_response(500, "Internal Server Error", str(e)) + logging.error(e.args) + return jsonify(result), 500 diff --git a/edge_cloud_management_api/specification/openapi.yaml b/edge_cloud_management_api/specification/openapi.yaml index 66776ee..e2d5c54 100644 --- a/edge_cloud_management_api/specification/openapi.yaml +++ b/edge_cloud_management_api/specification/openapi.yaml @@ -817,12 +817,7 @@ paths: "405": description: Method not allowed "404": -<<<<<<< HEAD description: Session not found -======= - description: Session not found - ->>>>>>> f18e931881554973db7ae6241588db6e667dbf10 /partner: post: tags: -- GitLab