Resolve "Logging CCF use redis to send event service api invocation"

Closes #38 (closed)

Merge request reports

Loading
+0 −13
Changes for services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/controllers/default_controller.py: 0 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ from ..core.publisher import Publisher
from functools import wraps

invoker_operations = InvokerManagementOperations()
publisher_ops = Publisher()
valid_user = ControlAccess()


@@ -59,11 +58,6 @@ def onboarded_invokers_onboarding_id_delete(onboarding_id): # noqa: E501
    current_app.logger.info("Removing invoker")
    res = invoker_operations.remove_apiinvokerenrolmentdetail(onboarding_id)

    if res.status_code == 204:
        current_app.logger.info("Invoker Removed")
        publisher_ops.publish_message("events", "API_INVOKER_OFFBOARDED")
        publisher_ops.publish_message("internal-messages", f"invoker-removed:{onboarding_id}")

    return res

@cert_validation()
@@ -84,10 +78,6 @@ def onboarded_invokers_onboarding_id_put(onboarding_id, body): # noqa: E501
        body = APIInvokerEnrolmentDetails.from_dict(connexion.request.get_json())  # noqa: E501
    res = invoker_operations.update_apiinvokerenrolmentdetail(onboarding_id,body)

    if res.status_code == 200:
        current_app.logger.info("Invoker Updated")
        publisher_ops.publish_message("events", "API_INVOKER_UPDATED")

    return res


@@ -111,8 +101,5 @@ def onboarded_invokers_post(body): # noqa: E501

    current_app.logger.info("Creating Invoker")
    res = invoker_operations.add_apiinvokerenrolmentdetail(body, username, uuid)
    if res.status_code == 201:
        current_app.logger.info("Invoker Created")
        publisher_ops.publish_message("events", "API_INVOKER_ONBOARDED")

    return res
+16 −3
Changes for services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/apiinvokerenrolmentdetails.py: 16 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -11,9 +11,10 @@ from .auth_manager import AuthManager
from .resources import Resource
from ..config import Config
from api_invoker_management.models.api_invoker_enrolment_details import APIInvokerEnrolmentDetails
from .redis_event import RedisEvent
from .publisher import Publisher



publisher_ops = Publisher()
class InvokerManagementOperations(Resource):

    def __check_api_invoker_id(self, api_invoker_id):
@@ -93,6 +94,10 @@ class InvokerManagementOperations(Resource):

        res = make_response(object=apiinvokerenrolmentdetail, status=201)
        res.headers['Location'] = "/api-invoker-management/v1/onboardedInvokers/" + str(api_invoker_id)

        if res.status_code == 201:
            current_app.logger.info("Invoker Created")
            RedisEvent("API_INVOKER_ONBOARDED", "apiInvokerIds", [str(api_invoker_id)]).send_event()
        return res

        # except Exception as e:
@@ -130,6 +135,9 @@ class InvokerManagementOperations(Resource):
            current_app.logger.debug("Invoker Resource inserted in database")

            res = make_response(object=APIInvokerEnrolmentDetails().from_dict(dict_to_camel_case(result)), status=200)
            if res.status_code == 200:
                current_app.logger.info("Invoker Updated")
                RedisEvent("API_INVOKER_UPDATED", "apiInvokerIds", [onboard_id]).send_event()
            return res

        except Exception as e:
@@ -153,7 +161,12 @@ class InvokerManagementOperations(Resource):
            current_app.logger.debug("Invoker resource removed from database")
            current_app.logger.debug("Netapp offboarded sucessfuly")
            out =  "The Netapp matching onboardingId  " + onboard_id + " was offboarded."
            return make_response(out, status=204)
            res = make_response(out, status=204)
            if res.status_code == 204:
                current_app.logger.info("Invoker Removed")
                RedisEvent("API_INVOKER_OFFBOARDED", "apiInvokerIds", [onboard_id]).send_event()
                publisher_ops.publish_message("internal-messages", f"invoker-removed:{onboard_id}")
            return res

        except Exception as e:
            exception = "An exception occurred in remove invoker"
+41 −0
Changes for services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/core/redis_event.py: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
from ..encoder import JSONEncoder
from .publisher import Publisher
import json

publisher_ops = Publisher()


class RedisEvent():
    def __init__(self, event, event_detail_key=None, information=None) -> None:
        self.EVENTS_ENUM = [
            'SERVICE_API_AVAILABLE',
            'SERVICE_API_UNAVAILABLE',
            'SERVICE_API_UPDATE',
            'API_INVOKER_ONBOARDED',
            'API_INVOKER_OFFBOARDED',
            'SERVICE_API_INVOCATION_SUCCESS',
            'SERVICE_API_INVOCATION_FAILURE',
            'ACCESS_CONTROL_POLICY_UPDATE',
            'ACCESS_CONTROL_POLICY_UNAVAILABLE',
            'API_INVOKER_AUTHORIZATION_REVOKED',
            'API_INVOKER_UPDATED',
            'API_TOPOLOGY_HIDING_CREATED',
            'API_TOPOLOGY_HIDING_REVOKED']
        if event not in self.EVENTS_ENUM:
            raise Exception(
                "Event (" + event + ") is not on event enum (" + ','.join(self.EVENTS_ENUM) + ")")
        self.redis_event = {
            "event": event
        }
        if event_detail_key != None and information != None:
            self.redis_event['key'] = event_detail_key
            self.redis_event['information'] = information

    def to_string(self):
        return json.dumps(self.redis_event, cls=JSONEncoder)

    def send_event(self):
        publisher_ops.publish_message("events", self.to_string())

    def __call__(self):
        return self.redis_event
+1 −1
Changes for services/TS29222_CAPIF_API_Provider_Management_API/api_provider_management/core/provider_enrolment_details_api.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ class ProviderManagementOperations(Resource):

            self.auth_manager.remove_auth_provider([apf_id[0], aef_id[0], amf_id[0]])

            self.publish_ops.publish_message("internal-messages", f"provider-removed:{aef_id[0]}:{apf_id[0]}")
            self.publish_ops.publish_message("internal-messages", f"provider-removed:{aef_id[0]}:{apf_id[0]}:{amf_id[0]}")
            return make_response(object=out, status=204)

        except Exception as e:
+4 −4
Changes for services/TS29222_CAPIF_Access_Control_Policy_API/openapi_server/core/accesscontrolpolicyapi.py: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@ class accessControlPolicyApi(Resource):
            projection = {"_id":0}

            if api_invoker_id is not None:
                query['apiInvokerPolicies.api_invoker_id'] = api_invoker_id
                projection['apiInvokerPolicies.$'] = 1
                query['api_invoker_policies.api_invoker_id'] = api_invoker_id
                projection['api_invoker_policies.$'] = 1
            if supported_features is not None:
                current_app.logger.debug(f"SupportedFeatures present on query with value {supported_features}, but currently not used")
            
@@ -37,8 +37,8 @@ class accessControlPolicyApi(Resource):

            current_app.logger.debug(policies)

            api_invoker_policies = policies[0]['apiInvokerPolicies']
            current_app.logger.debug(f"apiinvokerPolicies: {api_invoker_policies}")
            api_invoker_policies = policies[0]['api_invoker_policies']
            current_app.logger.debug(f"api_invoker_policies: {api_invoker_policies}")
            if not api_invoker_policies:
                current_app.logger.info(f"ACLs list is present but empty, then no ACLs found for the requested service: {service_api_id}, aef_id: {aef_id}, invoker: {api_invoker_id} and supportedFeatures: {supported_features}")
                #Not found error
Loading
Loading