diff --git a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/controllers/default_controller.py b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/controllers/default_controller.py index 9ea3c42833a20adcf5d6ef598fc17de3efdfd644..f2b0df69780e4ebde99f3df1a43fb34bca9805b9 100644 --- a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/controllers/default_controller.py +++ b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/controllers/default_controller.py @@ -8,7 +8,6 @@ from flask import Response, request, current_app from flask_jwt_extended import jwt_required, get_jwt_identity from cryptography import x509 from cryptography.hazmat.backends import default_backend -from ..core.publisher import Publisher from functools import wraps invoker_operations = InvokerManagementOperations() diff --git a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/apiinvokerenrolmentdetails.py b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/apiinvokerenrolmentdetails.py index 995df867c3f912e02497eee8435d4bada4145756..bcf1905da8b4f3a5901a833fad70112740877c8b 100644 --- a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/apiinvokerenrolmentdetails.py +++ b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/apiinvokerenrolmentdetails.py @@ -6,7 +6,7 @@ from .responses import bad_request_error, not_found_error, forbidden_error, inte from flask import current_app, Flask, Response import json from datetime import datetime -from ..util import dict_to_camel_case, clean_empty +from ..util import dict_to_camel_case, clean_empty, serialize_clean_camel_case from .auth_manager import AuthManager from .resources import Resource from ..config import Config @@ -91,7 +91,7 @@ class InvokerManagementOperations(Resource): self.auth_manager.add_auth_invoker(cert['data']['certificate'], api_invoker_id) - res = make_response(object=dict_to_camel_case(clean_empty(apiinvokerenrolmentdetail.to_dict())), status=201) + res = make_response(object=serialize_clean_camel_case(apiinvokerenrolmentdetail), status=201) res.headers['Location'] = "/api-invoker-management/v1/onboardedInvokers/" + str(api_invoker_id) if res.status_code == 201: @@ -99,11 +99,6 @@ class InvokerManagementOperations(Resource): RedisEvent("API_INVOKER_ONBOARDED", "apiInvokerIds", [str(api_invoker_id)]).send_event() return res - # except Exception as e: - # exception = "An exception occurred in create invoker" - # current_app.logger.error(exception + "::" + str(e)) - # return internal_server_error(detail=exception, cause=str(e)) - def update_apiinvokerenrolmentdetail(self, onboard_id, apiinvokerenrolmentdetail): mycol = self.db.get_col_by_name(self.db.invoker_enrolment_details) @@ -135,7 +130,7 @@ class InvokerManagementOperations(Resource): invoker_updated = APIInvokerEnrolmentDetails().from_dict(dict_to_camel_case(result)) - res = make_response(object=dict_to_camel_case(clean_empty(invoker_updated.to_dict())), status=200) + res = make_response(object=serialize_clean_camel_case(invoker_updated), status=200) if res.status_code == 200: current_app.logger.info("Invoker Updated") RedisEvent("API_INVOKER_UPDATED", "apiInvokerIds", [onboard_id]).send_event() diff --git a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/responses.py b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/responses.py index 96ace13619f80f897251bf57a4ad2f9dfb1b755b..f647dbf7b3f5ca6fa7bd36367f863ba21e99f8f4 100644 --- a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/responses.py +++ b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/responses.py @@ -2,47 +2,40 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from flask import Response import json -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=404, mimetype=mimetype) \ No newline at end of file diff --git a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/validate_user.py b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/validate_user.py index bcf0d880f669fa3a298c08da63df17f58213d2ec..b1e7a9bf9c0bfd032b37e08ca47c2669c6999d09 100644 --- a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/validate_user.py +++ b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/validate_user.py @@ -4,7 +4,7 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from .resources import Resource from .responses import internal_server_error -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case class ControlAccess(Resource): @@ -20,9 +20,7 @@ class ControlAccess(Resource): if cert_entry is not None: if cert_entry["cert_signature"] != cert_signature: prob = ProblemDetails(title="Unauthorized", detail="User not authorized", cause="You are not the owner of this resource") - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=401, mimetype="application/json") except Exception as e: diff --git a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/util.py b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/util.py index 27ba971d63477ec583e6c0fe54097c652daab757..31af7ab10eab38338398dd85eadcfa42e500519d 100644 --- a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/util.py +++ b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/util.py @@ -4,6 +4,14 @@ import six import typing_utils +def serialize_clean_camel_case(obj): + res = obj.to_dict() + res = clean_empty(res) + res = dict_to_camel_case(res) + + return res + + def clean_empty(d): if isinstance(d, dict): return { @@ -23,8 +31,11 @@ def dict_to_camel_case(my_dict): for attr, value in my_dict.items(): - my_key = ''.join(word.title() for word in attr.split('_')) - my_key= ''.join([my_key[0].lower(), my_key[1:]]) + if len(attr.split('_')) != 1: + my_key = ''.join(word.title() for word in attr.split('_')) + my_key = ''.join([my_key[0].lower(), my_key[1:]]) + else: + my_key = attr if isinstance(value, list): result[my_key] = list(map( diff --git a/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/provider_enrolment_details_api.py b/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/provider_enrolment_details_api.py index 0b54ee8152e85552bd99c5d64560498e67e69721..30760b996db7ae7fbbc5fcd212bfaf979dc8a7f2 100644 --- a/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/provider_enrolment_details_api.py +++ b/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/provider_enrolment_details_api.py @@ -5,7 +5,7 @@ from flask import current_app, Flask, Response from ..core.sign_certificate import sign_certificate from .responses import internal_server_error, not_found_error, forbidden_error, make_response, bad_request_error from datetime import datetime -from ..util import dict_to_camel_case, clean_empty +from ..util import dict_to_camel_case, clean_empty, serialize_clean_camel_case from .resources import Resource from .auth_manager import AuthManager @@ -64,7 +64,7 @@ class ProviderManagementOperations(Resource): current_app.logger.debug("Provider inserted in database") - res = make_response(object=dict_to_camel_case(api_provider_enrolment_details.to_dict()), status=201) + res = make_response(object=serialize_clean_camel_case(api_provider_enrolment_details), status=201) res.headers['Location'] = "/api-provider-management/v1/registrations/" + str(api_provider_enrolment_details.api_prov_dom_id) return res @@ -138,7 +138,8 @@ class ProviderManagementOperations(Resource): current_app.logger.debug("Provider domain updated in database") provider_updated = APIProviderEnrolmentDetails().from_dict(dict_to_camel_case(result)) - return make_response(object=dict_to_camel_case(provider_updated.to_dict()), status=200) + + return make_response(object=serialize_clean_camel_case(provider_updated), status=200) except Exception as e: exception = "An exception occurred in update provider" @@ -164,7 +165,8 @@ class ProviderManagementOperations(Resource): current_app.logger.debug("Provider domain updated in database") provider_updated = APIProviderEnrolmentDetails().from_dict(dict_to_camel_case(result)) - return make_response(object=dict_to_camel_case(provider_updated.to_dict()), status=200) + + return make_response(object=serialize_clean_camel_case(provider_updated), status=200) except Exception as e: exception = "An exception occurred in patch provider" diff --git a/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/responses.py b/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/responses.py index 4ad6bb852aa030e61f7c9e21d1ba80ec1866dbee..98eca0c9453aa3eaf676c209e9f2708b2b2d44e2 100644 --- a/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/responses.py +++ b/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/responses.py @@ -1,6 +1,6 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case from flask import Response, current_app import json @@ -15,35 +15,27 @@ def make_response(object, status): def internal_server_error(detail, cause): prob = ProblemDetails(title="Internal Server Error", status=500, detail=detail, cause=cause) + prob = serialize_clean_camel_case(prob) - prob = prob.to_dict() - prob = clean_empty(prob) - - return Response(json.dumps(dict_to_camel_case(prob), 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 = serialize_clean_camel_case(prob) - prob = prob.to_dict() - prob = clean_empty(prob) - - return Response(json.dumps(dict_to_camel_case(prob), 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 = serialize_clean_camel_case(prob) - prob = prob.to_dict() - prob = clean_empty(prob) - - return Response(json.dumps(dict_to_camel_case(prob), 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 = serialize_clean_camel_case(prob) - prob = prob.to_dict() - prob = clean_empty(prob) - - return Response(json.dumps(dict_to_camel_case(prob), cls=JSONEncoder), status=404, mimetype=mimetype) \ No newline at end of file + return Response(json.dumps(prob, cls=JSONEncoder), status=404, mimetype=mimetype) \ No newline at end of file diff --git a/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/validate_user.py b/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/validate_user.py index 4a9445dcac121dd9c073cab1bd3cca64e4e849b8..29043d520f6bfab2f3be3b0b63479440a4ba8aad 100644 --- a/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/validate_user.py +++ b/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/validate_user.py @@ -4,7 +4,8 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from .resources import Resource from .responses import internal_server_error -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case + class ControlAccess(Resource): @@ -19,9 +20,7 @@ class ControlAccess(Resource): if cert_entry is not None: if cert_entry["cert_signature"] != cert_signature: prob = ProblemDetails(title="Unauthorized", detail="User not authorized", cause="You are not the owner of this resource") - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=401, mimetype="application/json") except Exception as e: diff --git a/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/util.py b/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/util.py index 6fc44d5dbab0b9106f0531b8296b0197f8f927ff..431a28c6f522dec54599eb6e30ac9f9e4a040d49 100644 --- a/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/util.py +++ b/services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/util.py @@ -2,6 +2,15 @@ import datetime import six import typing_utils + +def serialize_clean_camel_case(obj): + res = obj.to_dict() + res = clean_empty(res) + res = dict_to_camel_case(res) + + return res + + def clean_empty(d): if isinstance(d, dict): return { @@ -13,6 +22,7 @@ def clean_empty(d): return [v for v in map(clean_empty, d) if v] return d + def dict_to_camel_case(my_dict): @@ -20,8 +30,11 @@ def dict_to_camel_case(my_dict): for attr, value in my_dict.items(): - my_key = ''.join(word.title() for word in attr.split('_')) - my_key= ''.join([my_key[0].lower(), my_key[1:]]) + if len(attr.split('_')) != 1: + my_key = ''.join(word.title() for word in attr.split('_')) + my_key = ''.join([my_key[0].lower(), my_key[1:]]) + else: + my_key = attr if isinstance(value, list): result[my_key] = list(map( @@ -38,6 +51,7 @@ def dict_to_camel_case(my_dict): return result + def _deserialize(data, klass): """Deserializes dict, list, str into an object. diff --git a/services/TS29222_CAPIF_Access_Control_Policy_API/Dockerfile b/services/TS29222_CAPIF_Access_Control_Policy_API/Dockerfile index c69bd56afa7c975dd03c3f83115145b076594dd1..9c1382590feac6390a85c9ac48dc55b64b805496 100644 --- a/services/TS29222_CAPIF_Access_Control_Policy_API/Dockerfile +++ b/services/TS29222_CAPIF_Access_Control_Policy_API/Dockerfile @@ -11,6 +11,4 @@ COPY . /usr/src/app EXPOSE 8080 -ENTRYPOINT ["gunicorn"] - -CMD ["--bind", "0.0.0.0:8080", "--chdir", "/usr/src/app/capif_acl", "wsgi:app"] \ No newline at end of file +CMD ["sh", "prepare_capif_acl.sh"] \ No newline at end of file diff --git a/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/core/accesscontrolpolicyapi.py b/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/core/accesscontrolpolicyapi.py index d82ac984b04e746ad372a3e0574a67e50a77d88f..48bf04e69b04e537e5c3de4f957a87fabe8125c8 100644 --- a/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/core/accesscontrolpolicyapi.py +++ b/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/core/accesscontrolpolicyapi.py @@ -2,7 +2,7 @@ from ..core.resources import Resource from flask import current_app from .responses import make_response, not_found_error, internal_server_error from ..models.access_control_policy_list import AccessControlPolicyList -from ..util import dict_to_camel_case, clean_empty +from ..util import dict_to_camel_case, clean_empty, serialize_clean_camel_case class accessControlPolicyApi(Resource): @@ -46,9 +46,8 @@ class accessControlPolicyApi(Resource): return not_found_error(f"No ACLs found for the requested service: {service_api_id}, aef_id: {aef_id}, invoker: {api_invoker_id} and supportedFeatures: {supported_features}", "Wrong id") acl = AccessControlPolicyList(api_invoker_policies) - response = clean_empty(acl.to_dict()) - return make_response(object=dict_to_camel_case(response), status=200) - + return make_response(object=serialize_clean_camel_case(acl), status=200) + except Exception as e: exception = "An exception occurred in get acl" current_app.logger.error(exception + "::" + str(e)) diff --git a/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/core/responses.py b/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/core/responses.py index 9d5ea092050de02f5813149bde790f9becaa3c90..9f8c3e665d94e8d98044638870dcc65a9dab1a91 100644 --- a/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/core/responses.py +++ b/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/core/responses.py @@ -1,7 +1,7 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from flask import Response -from ..util import dict_to_camel_case, clean_empty +from ..util import dict_to_camel_case, clean_empty, serialize_clean_camel_case import json mimetype = "application/json" @@ -15,39 +15,27 @@ def make_response(object, status): def internal_server_error(detail, cause): prob = ProblemDetails(title="Internal Server Error", status=500, detail=detail, cause=cause) - - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=404, mimetype=mimetype) \ No newline at end of file diff --git a/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/util.py b/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/util.py index 27903905e56c3a50fd6e8ee7ca314a931e2e494e..72d18d9b7df0bfd24490b24c4b9d9bcd683ad9ef 100644 --- a/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/util.py +++ b/services/TS29222_CAPIF_Access_Control_Policy_API/capif_acl/util.py @@ -4,6 +4,14 @@ import six import typing_utils +def serialize_clean_camel_case(obj): + res = obj.to_dict() + res = clean_empty(res) + res = dict_to_camel_case(res) + + return res + + def clean_empty(d): if isinstance(d, dict): return { @@ -23,8 +31,11 @@ def dict_to_camel_case(my_dict): for attr, value in my_dict.items(): - my_key = ''.join(word.title() for word in attr.split('_')) - my_key= ''.join([my_key[0].lower(), my_key[1:]]) + if len(attr.split('_')) != 1: + my_key = ''.join(word.title() for word in attr.split('_')) + my_key = ''.join([my_key[0].lower(), my_key[1:]]) + else: + my_key = attr if isinstance(value, list): result[my_key] = list(map( diff --git a/services/TS29222_CAPIF_Access_Control_Policy_API/prepare_capif_acl.sh b/services/TS29222_CAPIF_Access_Control_Policy_API/prepare_capif_acl.sh new file mode 100644 index 0000000000000000000000000000000000000000..fd0077ff49fd19e6e396a8253c2b63ce93e0c7c9 --- /dev/null +++ b/services/TS29222_CAPIF_Access_Control_Policy_API/prepare_capif_acl.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gunicorn --bind 0.0.0.0:8080 \ + --chdir /usr/src/app/capif_acl wsgi:app \ No newline at end of file diff --git a/services/TS29222_CAPIF_Auditing_API/Dockerfile b/services/TS29222_CAPIF_Auditing_API/Dockerfile index 4908c19cbc4b57479053a5f908561f10da17d7eb..1d1de3244165065973eec8ff86e502001b178373 100644 --- a/services/TS29222_CAPIF_Auditing_API/Dockerfile +++ b/services/TS29222_CAPIF_Auditing_API/Dockerfile @@ -12,6 +12,4 @@ COPY . /usr/src/app EXPOSE 8080 -ENTRYPOINT ["gunicorn"] - -CMD ["--bind", "0.0.0.0:8080", "--chdir", "/usr/src/app/logs", "wsgi:app"] \ No newline at end of file +CMD ["sh", "prepare_audit.sh"] \ No newline at end of file diff --git a/services/TS29222_CAPIF_Auditing_API/logs/core/auditoperations.py b/services/TS29222_CAPIF_Auditing_API/logs/core/auditoperations.py index 6632d2808e8ec3f82bf19ff9a2a947dc1b6de2c6..f74ec112e2aa73c682463ca6d0502e0ae503e1c3 100644 --- a/services/TS29222_CAPIF_Auditing_API/logs/core/auditoperations.py +++ b/services/TS29222_CAPIF_Auditing_API/logs/core/auditoperations.py @@ -4,7 +4,7 @@ import json from .resources import Resource -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case from .responses import bad_request_error, not_found_error, forbidden_error, internal_server_error, make_response from ..models.invocation_log import InvocationLog @@ -57,7 +57,7 @@ class AuditOperations (Resource): invocation_log = InvocationLog(result['aef_id'], result['api_invoker_id'], result['logs'], result['supported_features']) - res = make_response(object=dict_to_camel_case(clean_empty(invocation_log.to_dict())), status=200) + res = make_response(object=serialize_clean_camel_case(invocation_log), status=200) current_app.logger.debug("Found invocation logs") return res diff --git a/services/TS29222_CAPIF_Auditing_API/logs/core/responses.py b/services/TS29222_CAPIF_Auditing_API/logs/core/responses.py index 9d5ea092050de02f5813149bde790f9becaa3c90..89689a9e7b3a936e3ea953ed621853ce164d2d70 100644 --- a/services/TS29222_CAPIF_Auditing_API/logs/core/responses.py +++ b/services/TS29222_CAPIF_Auditing_API/logs/core/responses.py @@ -1,7 +1,7 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from flask import Response -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case import json mimetype = "application/json" @@ -15,39 +15,27 @@ def make_response(object, status): def internal_server_error(detail, cause): prob = ProblemDetails(title="Internal Server Error", status=500, detail=detail, cause=cause) - - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=404, mimetype=mimetype) \ No newline at end of file diff --git a/services/TS29222_CAPIF_Auditing_API/logs/util.py b/services/TS29222_CAPIF_Auditing_API/logs/util.py index ec1430110f5a167f67a8c083cfda84af63a678d4..d5deea1b7202ee5b603d373471d763f5953e6f2e 100644 --- a/services/TS29222_CAPIF_Auditing_API/logs/util.py +++ b/services/TS29222_CAPIF_Auditing_API/logs/util.py @@ -4,6 +4,14 @@ import six import typing_utils +def serialize_clean_camel_case(obj): + res = obj.to_dict() + res = clean_empty(res) + res = dict_to_camel_case(res) + + return res + + def clean_empty(d): if isinstance(d, dict): return { @@ -23,8 +31,11 @@ def dict_to_camel_case(my_dict): for attr, value in my_dict.items(): - my_key = ''.join(word.title() for word in attr.split('_')) - my_key= ''.join([my_key[0].lower(), my_key[1:]]) + if len(attr.split('_')) != 1: + my_key = ''.join(word.title() for word in attr.split('_')) + my_key = ''.join([my_key[0].lower(), my_key[1:]]) + else: + my_key = attr if my_key == "serviceApiCategory": my_key = "serviceAPICategory" diff --git a/services/TS29222_CAPIF_Auditing_API/prepare_audit.sh b/services/TS29222_CAPIF_Auditing_API/prepare_audit.sh new file mode 100644 index 0000000000000000000000000000000000000000..e47912ba6dd4a46eccfdd31e89107c76a838e82b --- /dev/null +++ b/services/TS29222_CAPIF_Auditing_API/prepare_audit.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +gunicorn --bind 0.0.0.0:8080 \ + --chdir /usr/src/app/logs wsgi:app + + diff --git a/services/TS29222_CAPIF_Discover_Service_API/Dockerfile b/services/TS29222_CAPIF_Discover_Service_API/Dockerfile index 9f1d46ea6ee674e69b958e111488d41b7013028d..1478af82410e6e25457620961e115073ab1bcdbc 100644 --- a/services/TS29222_CAPIF_Discover_Service_API/Dockerfile +++ b/services/TS29222_CAPIF_Discover_Service_API/Dockerfile @@ -12,6 +12,4 @@ COPY . /usr/src/app EXPOSE 8080 -ENTRYPOINT ["gunicorn"] - -CMD ["--bind", "0.0.0.0:8080", "--chdir", "/usr/src/app/service_apis", "wsgi:app"] \ No newline at end of file +CMD ["sh", "prepare_discover.sh"] \ No newline at end of file diff --git a/services/TS29222_CAPIF_Discover_Service_API/prepare_discover.sh b/services/TS29222_CAPIF_Discover_Service_API/prepare_discover.sh new file mode 100644 index 0000000000000000000000000000000000000000..dd9ad7d8b8b4a431a0623ad1da3b3a0c38e684a1 --- /dev/null +++ b/services/TS29222_CAPIF_Discover_Service_API/prepare_discover.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +gunicorn --bind 0.0.0.0:8080 \ + --chdir /usr/src/app/service_apis wsgi:app + + diff --git a/services/TS29222_CAPIF_Discover_Service_API/service_apis/core/discoveredapis.py b/services/TS29222_CAPIF_Discover_Service_API/service_apis/core/discoveredapis.py index 9ad5462dfb1ae4ea1d2fb46851b6d8cc04959962..487ceb14b65d6b7cca68b665257e0023dbcf926d 100644 --- a/services/TS29222_CAPIF_Discover_Service_API/service_apis/core/discoveredapis.py +++ b/services/TS29222_CAPIF_Discover_Service_API/service_apis/core/discoveredapis.py @@ -2,7 +2,7 @@ from flask import current_app, Flask, Response from ..core.responses import internal_server_error, forbidden_error ,make_response, not_found_error from ..models.discovered_apis import DiscoveredAPIs -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case from ..core.resources import Resource @@ -42,8 +42,8 @@ class DiscoverApisOperations(Resource): if len(json_docs) == 0: return not_found_error(detail="API Invoker " + api_invoker_id + " has no API Published that accomplish filter conditions", cause="No API Published accomplish filter conditions") - apis_discoveres = DiscoveredAPIs(service_api_descriptions=json_docs) - res = make_response(object=dict_to_camel_case(clean_empty(apis_discoveres.to_dict())), status=200) + apis_discovered = DiscoveredAPIs(service_api_descriptions=json_docs) + res = make_response(object=serialize_clean_camel_case(apis_discovered), status=200) return res except Exception as e: diff --git a/services/TS29222_CAPIF_Discover_Service_API/service_apis/core/responses.py b/services/TS29222_CAPIF_Discover_Service_API/service_apis/core/responses.py index df9905f96f4eaa990334d30c8b99fd58521cd28a..b54555bf6178395418c0e3d378feddf6fe072f3f 100644 --- a/services/TS29222_CAPIF_Discover_Service_API/service_apis/core/responses.py +++ b/services/TS29222_CAPIF_Discover_Service_API/service_apis/core/responses.py @@ -1,48 +1,41 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from flask import Response -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=404, mimetype=mimetype) \ No newline at end of file diff --git a/services/TS29222_CAPIF_Discover_Service_API/service_apis/util.py b/services/TS29222_CAPIF_Discover_Service_API/service_apis/util.py index c39e5fabe5806ecc746990ca002cbedb72676827..cfa4391ef80ec1d4177c26ba64e08795b28c8397 100644 --- a/services/TS29222_CAPIF_Discover_Service_API/service_apis/util.py +++ b/services/TS29222_CAPIF_Discover_Service_API/service_apis/util.py @@ -3,6 +3,15 @@ import datetime import six import typing_utils + +def serialize_clean_camel_case(obj): + res = obj.to_dict() + res = clean_empty(res) + res = dict_to_camel_case(res) + + return res + + def clean_empty(d): if isinstance(d, dict): return { @@ -14,6 +23,7 @@ def clean_empty(d): return [v for v in map(clean_empty, d) if v] return d + def dict_to_camel_case(my_dict): @@ -21,8 +31,12 @@ def dict_to_camel_case(my_dict): for attr, value in my_dict.items(): - my_key = ''.join(word.title() for word in attr.split('_')) - my_key= ''.join([my_key[0].lower(), my_key[1:]]) + if len(attr.split('_')) != 1: + my_key = ''.join(word.title() for word in attr.split('_')) + my_key = ''.join([my_key[0].lower(), my_key[1:]]) + else: + my_key = attr + if my_key == "serviceApiCategory": my_key = "serviceAPICategory" elif my_key == "serviceApiDescriptions": diff --git a/services/TS29222_CAPIF_Events_API/Dockerfile b/services/TS29222_CAPIF_Events_API/Dockerfile index 1fef3f2ede15e1de5674980d38a35fbbeebb6c7b..b8ba685688c633bd6ea2957c85839d6bf8a5555d 100644 --- a/services/TS29222_CAPIF_Events_API/Dockerfile +++ b/services/TS29222_CAPIF_Events_API/Dockerfile @@ -13,6 +13,4 @@ COPY . /usr/src/app EXPOSE 8080 -ENTRYPOINT ["gunicorn"] - -CMD ["--bind", "0.0.0.0:8080", "--chdir", "/usr/src/app/capif_events", "wsgi:app"] \ No newline at end of file +CMD ["sh", "prepare_events.sh"] \ No newline at end of file diff --git a/services/TS29222_CAPIF_Events_API/capif_events/core/events_apis.py b/services/TS29222_CAPIF_Events_API/capif_events/core/events_apis.py index d6b5bdff29dcec3161150bd42b8c24b62636633b..14cddb0c1501edcf9f17426b59789a3fd23a5196 100644 --- a/services/TS29222_CAPIF_Events_API/capif_events/core/events_apis.py +++ b/services/TS29222_CAPIF_Events_API/capif_events/core/events_apis.py @@ -12,9 +12,10 @@ from .resources import Resource from bson import json_util from .responses import internal_server_error, not_found_error, make_response, bad_request_error from ..db.db import MongoDatabse -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case from .auth_manager import AuthManager + class EventSubscriptionsOperations(Resource): def __check_subscriber_id(self, subscriber_id): @@ -73,7 +74,7 @@ class EventSubscriptionsOperations(Resource): self.auth_manager.add_auth_event(subscription_id, subscriber_id) - res = make_response(object=dict_to_camel_case(clean_empty(event_subscription.to_dict())), status=201) + res = make_response(object=serialize_clean_camel_case(event_subscription), status=201) res.headers['Location'] = "http://localhost:8080/capif-events/v1/" + \ str(subscriber_id) + "/subscriptions/" + str(subscription_id) diff --git a/services/TS29222_CAPIF_Events_API/capif_events/core/notifications.py b/services/TS29222_CAPIF_Events_API/capif_events/core/notifications.py index 3b32d1106838fd9760afa1c4dedd2b5fc378d0db..e005e7a8f53c25b18d9ceb0232f41a4a6934a6d7 100644 --- a/services/TS29222_CAPIF_Events_API/capif_events/core/notifications.py +++ b/services/TS29222_CAPIF_Events_API/capif_events/core/notifications.py @@ -10,7 +10,7 @@ import json from flask import current_app import asyncio import aiohttp -from util import dict_to_camel_case, clean_empty +from util import dict_to_camel_case, clean_empty, serialize_clean_camel_case class Notifications(): @@ -36,7 +36,7 @@ class Notifications(): data = EventNotification(sub["subscription_id"], events=redis_event.get('event'), event_detail=event_detail) current_app.logger.debug(json.dumps(data.to_dict(),cls=JSONEncoder)) - asyncio.run(self.send(url, dict_to_camel_case(clean_empty(data.to_dict())))) + asyncio.run(self.send(url, serialize_clean_camel_case(data))) except Exception as e: current_app.logger.error("An exception occurred ::" + str(e)) diff --git a/services/TS29222_CAPIF_Events_API/capif_events/core/responses.py b/services/TS29222_CAPIF_Events_API/capif_events/core/responses.py index 7862390ddb6ad27d60a0e9a1d2e4f358111f2270..89689a9e7b3a936e3ea953ed621853ce164d2d70 100644 --- a/services/TS29222_CAPIF_Events_API/capif_events/core/responses.py +++ b/services/TS29222_CAPIF_Events_API/capif_events/core/responses.py @@ -1,48 +1,41 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from flask import Response -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=404, mimetype=mimetype) \ No newline at end of file diff --git a/services/TS29222_CAPIF_Events_API/capif_events/core/validate_user.py b/services/TS29222_CAPIF_Events_API/capif_events/core/validate_user.py index be87defb5d803bd80211c83f13a25c8d8fd53ec9..e7ddee1c50f58ef418483ab58056058f413bb62c 100644 --- a/services/TS29222_CAPIF_Events_API/capif_events/core/validate_user.py +++ b/services/TS29222_CAPIF_Events_API/capif_events/core/validate_user.py @@ -4,7 +4,8 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from .resources import Resource from .responses import internal_server_error -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case + class ControlAccess(Resource): @@ -19,10 +20,7 @@ class ControlAccess(Resource): if cert_entry is not None: if cert_entry["cert_signature"] != cert_signature or "event_subscriptions" not in cert_entry["resources"] or event_id not in cert_entry["resources"]["event_subscriptions"]: prob = ProblemDetails(title="Unauthorized", detail="User not authorized", cause="You are not the owner of this resource") - - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=401, mimetype="application/json") diff --git a/services/TS29222_CAPIF_Events_API/capif_events/util.py b/services/TS29222_CAPIF_Events_API/capif_events/util.py index f067fde2be418e00a062b17852b3f051171ea4ef..28a9e46b722f32c666f92850d09bf12d74b4d743 100644 --- a/services/TS29222_CAPIF_Events_API/capif_events/util.py +++ b/services/TS29222_CAPIF_Events_API/capif_events/util.py @@ -1,10 +1,17 @@ import datetime import six -import typing import typing_utils +def serialize_clean_camel_case(obj): + res = obj.to_dict() + res = clean_empty(res) + res = dict_to_camel_case(res) + + return res + + def clean_empty(d): if isinstance(d, dict): return { @@ -38,7 +45,6 @@ def dict_to_camel_case(my_dict): return result - def _deserialize(data, klass): """Deserializes dict, list, str into an object. diff --git a/services/TS29222_CAPIF_Events_API/prepare_events.sh b/services/TS29222_CAPIF_Events_API/prepare_events.sh new file mode 100644 index 0000000000000000000000000000000000000000..62bd7ee283c58a5e48b3cbc27c80bded443f1e14 --- /dev/null +++ b/services/TS29222_CAPIF_Events_API/prepare_events.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gunicorn --bind 0.0.0.0:8080 \ + --chdir /usr/src/app/capif_events wsgi:app diff --git a/services/TS29222_CAPIF_Logging_API_Invocation_API/Dockerfile b/services/TS29222_CAPIF_Logging_API_Invocation_API/Dockerfile index 4248907cc2319d8bf85ae446f9e9d77c1ea3be80..f7cd99b2c94367d6bd968f4ea597854e478ac9ec 100644 --- a/services/TS29222_CAPIF_Logging_API_Invocation_API/Dockerfile +++ b/services/TS29222_CAPIF_Logging_API_Invocation_API/Dockerfile @@ -12,6 +12,4 @@ COPY . /usr/src/app EXPOSE 8080 -ENTRYPOINT ["gunicorn"] - -CMD ["--bind", "0.0.0.0:8080", "--chdir", "/usr/src/app/api_invocation_logs", "wsgi:app"] \ No newline at end of file +CMD ["sh", "prepare_logging.sh"] \ No newline at end of file diff --git a/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/invocationlogs.py b/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/invocationlogs.py index 06e597cd2fe70812198b0cdb15df3ac6827708d4..bae9c5a4f26e04d589818041aba15aca27e491bf 100644 --- a/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/invocationlogs.py +++ b/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/invocationlogs.py @@ -5,7 +5,7 @@ import secrets from flask import current_app, Flask, Response from pymongo import ReturnDocument -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case from ..encoder import JSONEncoder from .resources import Resource @@ -122,7 +122,7 @@ class LoggingInvocationOperations(Resource): existing_invocationlog['logs'].append(updated_invocation_log) mycol.find_one_and_update(my_query, {"$set": existing_invocationlog}, projection={'_id': 0, 'log_id': 0}, return_document=ReturnDocument.AFTER, upsert=False) - res = make_response(object=dict_to_camel_case(clean_empty(invocationlog.to_dict())), status=201) + res = make_response(object=serialize_clean_camel_case(invocationlog), status=201) current_app.logger.debug("Invocation Logs response ready") apis_added = {log.api_id:log.api_name for log in invocationlog.logs} diff --git a/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/responses.py b/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/responses.py index 6940f646be2ef7a7b20fa33cc1b3b8e6ca008ffb..5c9803e85b6b639693ae33284b209ecbff38cc3a 100644 --- a/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/responses.py +++ b/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/responses.py @@ -1,7 +1,7 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from flask import Response -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case import json mimetype = "application/json" @@ -15,49 +15,34 @@ def make_response(object, status): def internal_server_error(detail, cause): prob = ProblemDetails(title="Internal Server Error", status=500, detail=detail, cause=cause) - - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=404, mimetype=mimetype) def unauthorized_error(detail, cause): prob = ProblemDetails(title="Unauthorized", status=401, detail=detail, cause=cause) - - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=401, mimetype=mimetype) \ No newline at end of file diff --git a/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/validate_user.py b/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/validate_user.py index 13d8b6ab7a82a8287308b347454a35dc6d719b26..d9f7d5dc16def3abb9f92c5e6a0905657e0ccf54 100644 --- a/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/validate_user.py +++ b/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/core/validate_user.py @@ -4,7 +4,7 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from .resources import Resource from .responses import internal_server_error -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case class ControlAccess(Resource): @@ -20,9 +20,7 @@ class ControlAccess(Resource): if cert_entry is not None: if cert_entry["cert_signature"] != cert_signature: prob = ProblemDetails(title="Unauthorized", detail="User not authorized", cause="You are not the owner of this resource") - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=401, mimetype="application/json") except Exception as e: diff --git a/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/util.py b/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/util.py index ec1430110f5a167f67a8c083cfda84af63a678d4..baaea564448deb45d356e5149aac29a9459e16f5 100644 --- a/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/util.py +++ b/services/TS29222_CAPIF_Logging_API_Invocation_API/api_invocation_logs/util.py @@ -4,6 +4,14 @@ import six import typing_utils +def serialize_clean_camel_case(obj): + res = obj.to_dict() + res = clean_empty(res) + res = dict_to_camel_case(res) + + return res + + def clean_empty(d): if isinstance(d, dict): return { @@ -23,8 +31,12 @@ def dict_to_camel_case(my_dict): for attr, value in my_dict.items(): - my_key = ''.join(word.title() for word in attr.split('_')) - my_key= ''.join([my_key[0].lower(), my_key[1:]]) + if len(attr.split('_')) != 1: + my_key = ''.join(word.title() for word in attr.split('_')) + my_key = ''.join([my_key[0].lower(), my_key[1:]]) + else: + my_key = attr + if my_key == "serviceApiCategory": my_key = "serviceAPICategory" diff --git a/services/TS29222_CAPIF_Logging_API_Invocation_API/prepare_logging.sh b/services/TS29222_CAPIF_Logging_API_Invocation_API/prepare_logging.sh new file mode 100644 index 0000000000000000000000000000000000000000..4cd01a6ccf928e437c96462700e785422275913f --- /dev/null +++ b/services/TS29222_CAPIF_Logging_API_Invocation_API/prepare_logging.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gunicorn --bind 0.0.0.0:8080 \ + --chdir /usr/src/app/api_invocation_logs wsgi:app diff --git a/services/TS29222_CAPIF_Publish_Service_API/Dockerfile b/services/TS29222_CAPIF_Publish_Service_API/Dockerfile index c11e2d64a014a7a98ec58a902e9b64d26519f405..eca440204cf38f6f3ff1b27757be21deaaac7d09 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/Dockerfile +++ b/services/TS29222_CAPIF_Publish_Service_API/Dockerfile @@ -12,6 +12,4 @@ COPY . /usr/src/app EXPOSE 8080 -ENTRYPOINT ["gunicorn"] - -CMD ["--bind", "0.0.0.0:8080", "--chdir", "/usr/src/app/published_apis", "wsgi:app"] \ No newline at end of file +CMD ["sh", "prepare_publish.sh"] \ No newline at end of file diff --git a/services/TS29222_CAPIF_Publish_Service_API/prepare_publish.sh b/services/TS29222_CAPIF_Publish_Service_API/prepare_publish.sh new file mode 100644 index 0000000000000000000000000000000000000000..d0eed0b94e7189472bd6c659e4850b79adbf26f6 --- /dev/null +++ b/services/TS29222_CAPIF_Publish_Service_API/prepare_publish.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gunicorn --bind 0.0.0.0:8080 \ + --chdir /usr/src/app/published_apis wsgi:app diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/responses.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/responses.py index c61eae0c65bf15bf261139128c75a495799a927f..3d10ff541afe36f7c3bc527a8a475805e532cdcc 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/responses.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/responses.py @@ -1,7 +1,7 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from flask import Response -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case import json @@ -16,48 +16,34 @@ def make_response(object, status): def internal_server_error(detail, cause): prob = ProblemDetails(title="Internal Server Error", status=500, detail=detail, cause=cause) - - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=404, mimetype=mimetype) + def unauthorized_error(detail, cause): prob = ProblemDetails(title="Unauthorized", status=401, detail=detail, cause=cause) - - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=401, mimetype=mimetype) \ No newline at end of file diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 41ce03de2243a40442ec3cddd04b11eebf5018bf..f32b7b2c1e652e08bdc98734bc9003d04e170c63 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -4,7 +4,7 @@ from flask import current_app, Flask, Response from .resources import Resource from datetime import datetime -from ..util import dict_to_camel_case, clean_empty +from ..util import dict_to_camel_case, clean_empty, serialize_clean_camel_case from .responses import internal_server_error, forbidden_error, not_found_error, unauthorized_error, make_response from .auth_manager import AuthManager from .redis_event import RedisEvent @@ -110,7 +110,7 @@ class PublishServiceOperations(Resource): current_app.logger.debug("Service inserted in database") - res = make_response(object=dict_to_camel_case(clean_empty(serviceapidescription.to_dict())), status=201) + res = make_response(object=serialize_clean_camel_case(serviceapidescription), status=201) res.headers['Location'] = "http://localhost:8080/published-apis/v1/" + \ str(apf_id) + "/service-apis/" + str(api_id) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/validate_user.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/validate_user.py index 5eed2c946e1e8388518061b10a862143f6c1b82d..f48414943c1c384b10d52d21c1aac456a1d772bc 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/validate_user.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/validate_user.py @@ -4,7 +4,8 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from .resources import Resource from .responses import internal_server_error -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case + class ControlAccess(Resource): @@ -19,9 +20,7 @@ class ControlAccess(Resource): if cert_entry is not None: if cert_entry["cert_signature"] != cert_signature or "services" not in cert_entry["resources"] or service_id not in cert_entry["resources"]["services"]: prob = ProblemDetails(title="Unauthorized", detail="User not authorized", cause="You are not the owner of this resource") - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=401, mimetype="application/json") except Exception as e: diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/util.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/util.py index c43b2746c4085a6f6de5a3555a19f3848aa0ad40..3d85256f947326515afce40014c53420ef7c4879 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/util.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/util.py @@ -4,6 +4,14 @@ import six import typing_utils +def serialize_clean_camel_case(obj): + res = obj.to_dict() + res = clean_empty(res) + res = dict_to_camel_case(res) + + return res + + def clean_empty(d): if isinstance(d, dict): return { @@ -15,15 +23,19 @@ def clean_empty(d): return [v for v in map(clean_empty, d) if v] return d + def dict_to_camel_case(my_dict): result = {} for attr, value in my_dict.items(): + if len(attr.split('_')) != 1: + my_key = ''.join(word.title() for word in attr.split('_')) + my_key= ''.join([my_key[0].lower(), my_key[1:]]) + else: + my_key = attr - my_key = ''.join(word.title() for word in attr.split('_')) - my_key= ''.join([my_key[0].lower(), my_key[1:]]) if my_key == "serviceApiCategory": my_key = "serviceAPICategory" diff --git a/services/TS29222_CAPIF_Routing_Info_API/Dockerfile b/services/TS29222_CAPIF_Routing_Info_API/Dockerfile index cfa4b5dfe4888a1efa8fb9551f707f21c93dd73c..1ea2ba944b1644d32a1164368dd0d771edcb5ce0 100644 --- a/services/TS29222_CAPIF_Routing_Info_API/Dockerfile +++ b/services/TS29222_CAPIF_Routing_Info_API/Dockerfile @@ -11,6 +11,6 @@ COPY . /usr/src/app EXPOSE 8080 -ENTRYPOINT ["gunicorn"] +EXPOSE 8080 -CMD ["--bind", "0.0.0.0:8080", "--chdir", "/usr/src/app/capif_routing_info", "wsgi:app"] \ No newline at end of file +CMD ["sh", "prepare_routing_info.sh"] \ No newline at end of file diff --git a/services/TS29222_CAPIF_Routing_Info_API/capif_routing_info/util.py b/services/TS29222_CAPIF_Routing_Info_API/capif_routing_info/util.py index 910388bab6fa518b467b13476102000d2b0a0321..54a13013df3b7fde574d61407acd23d0223f0be3 100644 --- a/services/TS29222_CAPIF_Routing_Info_API/capif_routing_info/util.py +++ b/services/TS29222_CAPIF_Routing_Info_API/capif_routing_info/util.py @@ -1,7 +1,6 @@ import datetime import six -import typing import typing_utils diff --git a/services/TS29222_CAPIF_Routing_Info_API/prepare_routing_info.sh b/services/TS29222_CAPIF_Routing_Info_API/prepare_routing_info.sh new file mode 100644 index 0000000000000000000000000000000000000000..53eaa2b084e73d1fe7e710f1acf94b48771b668b --- /dev/null +++ b/services/TS29222_CAPIF_Routing_Info_API/prepare_routing_info.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gunicorn --bind 0.0.0.0:8080 \ + --chdir /usr/src/app/capif_routing_info wsgi:app diff --git a/services/TS29222_CAPIF_Security_API/Dockerfile b/services/TS29222_CAPIF_Security_API/Dockerfile index 9566c752eaa135a135faeb70c812db1d2d997c0a..9f73be9b86061f4cd1055ed23a54261db97853fd 100644 --- a/services/TS29222_CAPIF_Security_API/Dockerfile +++ b/services/TS29222_CAPIF_Security_API/Dockerfile @@ -15,4 +15,4 @@ COPY . /usr/src/app EXPOSE 8080 -CMD ["sh", "security_prepare.sh"] +CMD ["sh", "prepare_security.sh"] diff --git a/services/TS29222_CAPIF_Security_API/capif_security/core/responses.py b/services/TS29222_CAPIF_Security_API/capif_security/core/responses.py index 9c2020c79bb6e0cc6e68a084607a61d563c48657..4e1eb35cbaf62e88311170d3afee308ab7aa5b64 100644 --- a/services/TS29222_CAPIF_Security_API/capif_security/core/responses.py +++ b/services/TS29222_CAPIF_Security_API/capif_security/core/responses.py @@ -2,7 +2,7 @@ from ..models.problem_details import ProblemDetails from ..encoder import JSONEncoder from flask import Response import json -from ..util import dict_to_camel_case, clean_empty +from ..util import serialize_clean_camel_case mimetype = "application/json" @@ -15,49 +15,34 @@ def make_response(object, status): def internal_server_error(detail, cause): prob = ProblemDetails(title="Internal Server Error", status=500, detail=detail, cause=cause) - - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) 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 = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=404, mimetype=mimetype) def unauthorized_error(detail, cause): prob = ProblemDetails(title="Unauthorized", status=401, detail=detail, cause=cause) - - prob = prob.to_dict() - prob = clean_empty(prob) - prob = dict_to_camel_case(prob) + prob = serialize_clean_camel_case(prob) return Response(json.dumps(prob, cls=JSONEncoder), status=401, mimetype=mimetype) \ No newline at end of file diff --git a/services/TS29222_CAPIF_Security_API/capif_security/core/servicesecurity.py b/services/TS29222_CAPIF_Security_API/capif_security/core/servicesecurity.py index 36a0895ecd0b1add2e6a1438730b7e3f7d2d92f9..c754a314e3a3af554d9ed90cac19d036ea88943c 100644 --- a/services/TS29222_CAPIF_Security_API/capif_security/core/servicesecurity.py +++ b/services/TS29222_CAPIF_Security_API/capif_security/core/servicesecurity.py @@ -12,7 +12,7 @@ from ..core.publisher import Publisher from ..models.access_token_err import AccessTokenErr from ..models.access_token_rsp import AccessTokenRsp from ..models.access_token_claims import AccessTokenClaims -from ..util import dict_to_camel_case, clean_empty +from ..util import dict_to_camel_case, clean_empty, serialize_clean_camel_case from .responses import not_found_error, make_response, bad_request_error, internal_server_error, forbidden_error from .resources import Resource from .redis_event import RedisEvent @@ -196,7 +196,7 @@ class SecurityOperations(Resource): rec.update(service_security.to_dict()) mycol.insert_one(rec) - res = make_response(object=dict_to_camel_case(clean_empty(service_security.to_dict())), status=201) + res = make_response(object=serialize_clean_camel_case(service_security), status=201) res.headers['Location'] = "https://{}/capif-security/v1/trustedInvokers/{}".format( os.getenv('CAPIF_HOSTNAME'), str(api_invoker_id)) @@ -263,10 +263,9 @@ class SecurityOperations(Resource): invoker = invokers_col.find_one( {"api_invoker_id": access_token_req["client_id"]}) if invoker is None: - client_id_error = AccessTokenErr(error="invalid_client", error_description="Client Id not found") + client_id_error = AccessTokenErr(error="invalid_client", error_description="Client Id not found") return make_response(object=clean_empty(client_id_error.to_dict()), status=400) - if access_token_req["grant_type"] != "client_credentials": client_id_error = AccessTokenErr(error="unsupported_grant_type", error_description="Invalid value for `grant_type` ({0}), must be one of ['client_credentials'] - 'grant_type'" @@ -296,7 +295,6 @@ class SecurityOperations(Resource): current_app.logger.debug("Created access token") - # res = make_response(object=dict_to_camel_case(clean_empty(access_token_resp.to_dict())), status=200) res = make_response(object=clean_empty(access_token_resp.to_dict()), status=200) return res except Exception as e: diff --git a/services/TS29222_CAPIF_Security_API/capif_security/util.py b/services/TS29222_CAPIF_Security_API/capif_security/util.py index 00ceb152b3c95233fec243ca5e3b8304c4b3611c..72d18d9b7df0bfd24490b24c4b9d9bcd683ad9ef 100644 --- a/services/TS29222_CAPIF_Security_API/capif_security/util.py +++ b/services/TS29222_CAPIF_Security_API/capif_security/util.py @@ -4,6 +4,14 @@ import six import typing_utils +def serialize_clean_camel_case(obj): + res = obj.to_dict() + res = clean_empty(res) + res = dict_to_camel_case(res) + + return res + + def clean_empty(d): if isinstance(d, dict): return { @@ -15,6 +23,7 @@ def clean_empty(d): return [v for v in map(clean_empty, d) if v] return d + def dict_to_camel_case(my_dict): @@ -22,8 +31,11 @@ def dict_to_camel_case(my_dict): for attr, value in my_dict.items(): - my_key = ''.join(word.title() for word in attr.split('_')) - my_key= ''.join([my_key[0].lower(), my_key[1:]]) + if len(attr.split('_')) != 1: + my_key = ''.join(word.title() for word in attr.split('_')) + my_key = ''.join([my_key[0].lower(), my_key[1:]]) + else: + my_key = attr if isinstance(value, list): result[my_key] = list(map( @@ -41,7 +53,6 @@ def dict_to_camel_case(my_dict): return result - def _deserialize(data, klass): """Deserializes dict, list, str into an object. diff --git a/services/TS29222_CAPIF_Security_API/security_prepare.sh b/services/TS29222_CAPIF_Security_API/prepare_security.sh similarity index 100% rename from services/TS29222_CAPIF_Security_API/security_prepare.sh rename to services/TS29222_CAPIF_Security_API/prepare_security.sh diff --git a/services/helper/Dockerfile b/services/helper/Dockerfile index 2c521b77a2f232b87dd82c95f7f8fba652d083a7..36439567b9077997dac2b88cb1f362d3affd77e2 100644 --- a/services/helper/Dockerfile +++ b/services/helper/Dockerfile @@ -13,6 +13,4 @@ COPY . /usr/src/app EXPOSE 8080 -ENTRYPOINT ["gunicorn"] - -CMD ["--bind", "0.0.0.0:8080", "--chdir", "/usr/src/app/helper_service", "wsgi:app"] +CMD ["sh", "prepare_helper.sh"] diff --git a/services/helper/prepare_helper.sh b/services/helper/prepare_helper.sh new file mode 100644 index 0000000000000000000000000000000000000000..d4297f6484ddfe6ee867338b7d19b7eb97fc4b7d --- /dev/null +++ b/services/helper/prepare_helper.sh @@ -0,0 +1,5 @@ +#!/bin/bash + + +gunicorn --bind 0.0.0.0:8080 \ + --chdir /usr/src/app/helper_service wsgi:app \ No newline at end of file