diff --git a/edge_cloud_management_api/controllers/federation_manager_controller.py b/edge_cloud_management_api/controllers/federation_manager_controller.py index d2fbf4f7f0603cf7e088db03a7d6ae93960d997b..8a39a3780b12658ef0a5b32b6e04bfd7fd73e776 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 66776eedb79fb8d491241075822a88eec56da88b..e2d5c54a22a96d5eba5aaf193125d4e8889239d4 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: