Commit 35846b01 authored by Stavros-Anastasios Charismiadis's avatar Stavros-Anastasios Charismiadis
Browse files

Change ProblemDetails initialization to properly be serialized

parent b4c3c202
Loading
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -124,13 +124,12 @@ class ProviderManagementOperations(Resource):
                    for api_func in api_prov_funcs:
                        if func.api_prov_func_id == api_func["api_prov_func_id"]:
                            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"]:
                                certificate = sign_certificate(func.reg_info.api_prov_pub_key, api_func["api_prov_func_id"])
                                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)


            api_provider_enrolment_details = api_provider_enrolment_details.to_dict()
            api_provider_enrolment_details = clean_empty(api_provider_enrolment_details)

@@ -139,7 +138,9 @@ class ProviderManagementOperations(Resource):
            result = clean_empty(result)

            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:
            exception = "An exception occurred in update provider"
@@ -164,8 +165,9 @@ class ProviderManagementOperations(Resource):
            result = clean_empty(result)

            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:
            exception = "An exception occurred in patch provider"
+18 −8
Original line number Diff line number Diff line
from ..models.problem_details import ProblemDetails
from ..encoder import JSONEncoder
from ..util import dict_to_camel_case
from flask import Response
import json

mimetype = "application/json"


def make_response(object, status):
    res = Response(json.dumps(object, cls=JSONEncoder), status=status, mimetype=mimetype)

    return res


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):
    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):
    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):
    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)
 No newline at end of file
    return Response(json.dumps(dict_to_camel_case(prob.to_dict()), cls=JSONEncoder), status=404, mimetype=mimetype)
 No newline at end of file