Skip to content
Snippets Groups Projects
Commit 35846b01 authored by Stavros-Anastasios Charismiadis's avatar Stavros-Anastasios Charismiadis
Browse files

Change ProblemDetails initialization to properly be serialized

parent b4c3c202
No related branches found
No related tags found
3 merge requests!43Staging to Main for Release 1,!36Ocf37 change development flask server to production server (after some new changes in staging),!33Ocf37 change development flask server to production server
Pipeline #6026 failed
...@@ -124,13 +124,12 @@ class ProviderManagementOperations(Resource): ...@@ -124,13 +124,12 @@ class ProviderManagementOperations(Resource):
for api_func in api_prov_funcs: for api_func in api_prov_funcs:
if func.api_prov_func_id == api_func["api_prov_func_id"]: if func.api_prov_func_id == api_func["api_prov_func_id"]:
if func.api_prov_func_role != api_func["api_prov_func_role"]: if func.api_prov_func_role != api_func["api_prov_func_role"]:
return bad_request_error(detail="Bad Role in provider", cause="Different role in update reqeuest", invalid_params=[{"param":"api_prov_func_role","reason":"differente role with same id"}]) return bad_request_error(detail="Bad Role in provider", cause="Different role in update reqeuest", invalid_params=[{"param":"api_prov_func_role","reason":"different role with same id"}])
if func.reg_info.api_prov_pub_key != api_func["reg_info"]["api_prov_pub_key"]: if func.reg_info.api_prov_pub_key != api_func["reg_info"]["api_prov_pub_key"]:
certificate = sign_certificate(func.reg_info.api_prov_pub_key, api_func["api_prov_func_id"]) certificate = sign_certificate(func.reg_info.api_prov_pub_key, api_func["api_prov_func_id"])
func.reg_info.api_prov_cert = certificate func.reg_info.api_prov_cert = certificate
self.auth_manager.update_auth_provider(certificate, func.api_prov_func_id, api_prov_dom_id, func.api_prov_func_role) self.auth_manager.update_auth_provider(certificate, func.api_prov_func_id, api_prov_dom_id, func.api_prov_func_role)
api_provider_enrolment_details = api_provider_enrolment_details.to_dict() api_provider_enrolment_details = api_provider_enrolment_details.to_dict()
api_provider_enrolment_details = clean_empty(api_provider_enrolment_details) api_provider_enrolment_details = clean_empty(api_provider_enrolment_details)
...@@ -139,7 +138,9 @@ class ProviderManagementOperations(Resource): ...@@ -139,7 +138,9 @@ class ProviderManagementOperations(Resource):
result = clean_empty(result) result = clean_empty(result)
current_app.logger.debug("Provider domain updated in database") current_app.logger.debug("Provider domain updated in database")
return make_response(object=APIProviderEnrolmentDetails().from_dict(dict_to_camel_case(result)), status=200) provider_updated = APIProviderEnrolmentDetails().from_dict(dict_to_camel_case(result))
# return make_response(object=APIProviderEnrolmentDetails().from_dict(dict_to_camel_case(result)), status=200)
return make_response(object=dict_to_camel_case(provider_updated.to_dict()), status=200)
except Exception as e: except Exception as e:
exception = "An exception occurred in update provider" exception = "An exception occurred in update provider"
...@@ -164,8 +165,9 @@ class ProviderManagementOperations(Resource): ...@@ -164,8 +165,9 @@ class ProviderManagementOperations(Resource):
result = clean_empty(result) result = clean_empty(result)
current_app.logger.debug("Provider domain updated in database") current_app.logger.debug("Provider domain updated in database")
provider_updated = APIProviderEnrolmentDetails().from_dict(dict_to_camel_case(result))
return make_response(object=APIProviderEnrolmentDetails().from_dict(dict_to_camel_case(result)), status=200) # return make_response(object=APIProviderEnrolmentDetails().from_dict(dict_to_camel_case(result)), status=200)
return make_response(object=dict_to_camel_case(provider_updated.to_dict()), status=200)
except Exception as e: except Exception as e:
exception = "An exception occurred in patch provider" exception = "An exception occurred in patch provider"
......
from ..models.problem_details import ProblemDetails from ..models.problem_details import ProblemDetails
from ..encoder import JSONEncoder from ..encoder import JSONEncoder
from ..util import dict_to_camel_case
from flask import Response from flask import Response
import json import json
mimetype = "application/json" mimetype = "application/json"
def make_response(object, status): def make_response(object, status):
res = Response(json.dumps(object, cls=JSONEncoder), status=status, mimetype=mimetype) res = Response(json.dumps(object, cls=JSONEncoder), status=status, mimetype=mimetype)
return res return res
def internal_server_error(detail, cause): def internal_server_error(detail, cause):
prob = ProblemDetails(title="Internal Server Error", status=500, detail=detail, cause=cause) prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Internal Server Error", status=500, detail=detail, cause=cause, invalid_params=[{"param":"","reason":""}], supported_features="fffff")
# BEFORE: prob = ProblemDetails(title="Internal Server Error", status=500, detail=detail, cause=cause)
return Response(json.dumps(dict_to_camel_case(prob.to_dict()), cls=JSONEncoder), status=500, mimetype=mimetype)
return Response(json.dumps(prob, cls=JSONEncoder), status=500, mimetype=mimetype)
def forbidden_error(detail, cause): def forbidden_error(detail, cause):
prob = ProblemDetails(title="Forbidden", status=403, detail=detail, cause=cause) prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Forbidden", status=403, detail=detail, cause=cause, invalid_params=[{"param":"","reason":""}], supported_features="fffff")
# BEFORE: prob = ProblemDetails(title="Forbidden", status=403, detail=detail, cause=cause)
return Response(json.dumps(dict_to_camel_case(prob.to_dict()), cls=JSONEncoder), status=403, mimetype=mimetype)
return Response(json.dumps(prob, cls=JSONEncoder), status=403, mimetype=mimetype)
def bad_request_error(detail, cause, invalid_params): def bad_request_error(detail, cause, invalid_params):
prob = ProblemDetails(title="Bad Request", status=400, detail=detail, cause=cause, invalid_params=invalid_params) prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Bad Request", status=400, detail=detail, cause=cause, invalid_params=invalid_params, supported_features="fffff")
# BEFORE: prob = ProblemDetails(title="Bad Request", status=400, detail=detail, cause=cause, invalid_params=invalid_params)
return Response(json.dumps(dict_to_camel_case(prob.to_dict()), cls=JSONEncoder), status=400, mimetype=cause)
return Response(json.dumps(prob, cls=JSONEncoder), status=400, mimetype=cause)
def not_found_error(detail, cause): def not_found_error(detail, cause):
prob = ProblemDetails(title="Not Found", status=404, detail=detail, cause=cause) prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Not Found", status=404, detail=detail, cause=cause, invalid_params=[{"param":"","reason":""}], supported_features="fffff")
# BEFORE: prob = ProblemDetails(title="Not Found", status=404, detail=detail, cause=cause)
return Response(json.dumps(prob, cls=JSONEncoder), status=404, mimetype=mimetype) return Response(json.dumps(dict_to_camel_case(prob.to_dict()), cls=JSONEncoder), status=404, mimetype=mimetype)
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment