From 4fd63f005ff3a18dca0feb0606628d556316a3a3 Mon Sep 17 00:00:00 2001 From: Stavros-Anastasios Charismiadis Date: Fri, 21 Jun 2024 11:49:36 +0300 Subject: [PATCH 1/2] Add serialize_clean_camel_case function, prepare script for all APIs and fix bug in dict_to_camel_case --- .../core/apiinvokerenrolmentdetails.py | 11 ++------ .../api_invoker_management/core/responses.py | 27 +++++++----------- .../core/validate_user.py | 6 ++-- .../api_invoker_management/util.py | 15 ++++++++-- .../core/provider_enrolment_details_api.py | 10 ++++--- .../api_provider_management/core/responses.py | 26 ++++++----------- .../core/validate_user.py | 7 ++--- .../api_provider_management/util.py | 18 ++++++++++-- .../Dockerfile | 4 +-- .../capif_acl/core/accesscontrolpolicyapi.py | 7 ++--- .../capif_acl/core/responses.py | 22 ++++----------- .../capif_acl/util.py | 15 ++++++++-- .../prepare_capif_acl.sh | 4 +++ .../TS29222_CAPIF_Auditing_API/Dockerfile | 4 +-- .../logs/core/auditoperations.py | 4 +-- .../logs/core/responses.py | 22 ++++----------- .../TS29222_CAPIF_Auditing_API/logs/util.py | 15 ++++++++-- .../prepare_audit.sh | 6 ++++ .../Dockerfile | 4 +-- .../prepare_discover.sh | 6 ++++ .../service_apis/core/discoveredapis.py | 6 ++-- .../service_apis/core/responses.py | 27 +++++++----------- .../service_apis/util.py | 18 ++++++++++-- services/TS29222_CAPIF_Events_API/Dockerfile | 4 +-- .../capif_events/core/events_apis.py | 5 ++-- .../capif_events/core/notifications.py | 4 +-- .../capif_events/core/responses.py | 27 +++++++----------- .../capif_events/core/validate_user.py | 8 ++---- .../capif_events/util.py | 10 +++++-- .../prepare_events.sh | 4 +++ .../Dockerfile | 4 +-- .../core/invocationlogs.py | 4 +-- .../api_invocation_logs/core/responses.py | 27 ++++-------------- .../api_invocation_logs/core/validate_user.py | 6 ++-- .../api_invocation_logs/util.py | 16 +++++++++-- .../prepare_logging.sh | 4 +++ .../Dockerfile | 4 +-- .../prepare_publish.sh | 4 +++ .../published_apis/core/responses.py | 28 +++++-------------- .../core/serviceapidescriptions.py | 4 +-- .../published_apis/core/validate_user.py | 7 ++--- .../published_apis/util.py | 16 +++++++++-- .../TS29222_CAPIF_Routing_Info_API/Dockerfile | 4 +-- .../capif_routing_info/util.py | 1 - .../prepare_routing_info.sh | 4 +++ .../TS29222_CAPIF_Security_API/Dockerfile | 2 +- .../capif_security/core/responses.py | 27 ++++-------------- .../capif_security/core/servicesecurity.py | 8 ++---- .../capif_security/util.py | 17 +++++++++-- ...ecurity_prepare.sh => prepare_security.sh} | 0 services/helper/Dockerfile | 4 +-- services/helper/prepare_helper.sh | 5 ++++ 52 files changed, 278 insertions(+), 264 deletions(-) create mode 100644 services/TS29222_CAPIF_Access_Control_Policy_API/prepare_capif_acl.sh create mode 100644 services/TS29222_CAPIF_Auditing_API/prepare_audit.sh create mode 100644 services/TS29222_CAPIF_Discover_Service_API/prepare_discover.sh create mode 100644 services/TS29222_CAPIF_Events_API/prepare_events.sh create mode 100644 services/TS29222_CAPIF_Logging_API_Invocation_API/prepare_logging.sh create mode 100644 services/TS29222_CAPIF_Publish_Service_API/prepare_publish.sh create mode 100644 services/TS29222_CAPIF_Routing_Info_API/prepare_routing_info.sh rename services/TS29222_CAPIF_Security_API/{security_prepare.sh => prepare_security.sh} (100%) create mode 100644 services/helper/prepare_helper.sh 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 3c3c38b..ee052a4 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 96ace13..f647dbf 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 bcf0d88..b1e7a9b 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 27ba971..31af7ab 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 0b54ee8..30760b9 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 4ad6bb8..98eca0c 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 4a9445d..29043d5 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 6fc44d5..431a28c 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 c69bd56..9c13825 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 d82ac98..48bf04e 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 9d5ea09..9f8c3e6 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 2790390..72d18d9 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 0000000..fd0077f --- /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 4908c19..1d1de32 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 6632d28..f74ec11 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 9d5ea09..89689a9 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 ec14301..d5deea1 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 0000000..e47912b --- /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 9f1d46e..1478af8 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 0000000..dd9ad7d --- /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 9ad5462..487ceb1 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 df9905f..b54555b 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 c39e5fa..cfa4391 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 1fef3f2..b8ba685 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 d6b5bdf..14cddb0 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 3b32d11..e005e7a 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 7862390..89689a9 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 be87def..e7ddee1 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 f067fde..28a9e46 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 0000000..62bd7ee --- /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 4248907..f7cd99b 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 06e597c..bae9c5a 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 6940f64..5c9803e 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 13d8b6a..d9f7d5d 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 ec14301..baaea56 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 0000000..4cd01a6 --- /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 c11e2d6..eca4402 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 0000000..d0eed0b --- /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 c61eae0..3d10ff5 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 41ce03d..f32b7b2 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 5eed2c9..f484149 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 c43b274..3d85256 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 cfa4b5d..1ea2ba9 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 910388b..54a1301 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 0000000..53eaa2b --- /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 9566c75..9f73be9 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 9c2020c..4e1eb35 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 9fe7838..5daa097 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 00ceb15..72d18d9 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 2c521b7..3643956 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 0000000..d4297f6 --- /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 -- GitLab From 9820328651016d67192fd4ee44bf3434448245ab Mon Sep 17 00:00:00 2001 From: Stavros-Anastasios Charismiadis Date: Fri, 21 Jun 2024 12:46:01 +0300 Subject: [PATCH 2/2] remove unsed import --- .../api_invoker_management/controllers/default_controller.py | 1 - 1 file changed, 1 deletion(-) 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 9ea3c42..f2b0df6 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() -- GitLab