Commit 56fefdf6 authored by Jorge Moratinos's avatar Jorge Moratinos
Browse files

Merge branch 'OCF38-logging-ccf-use-redis-to-send-event-service-api-invocation' into 'staging'

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

Closes #38

See merge request !22
parents 1f72b5e2 cb619ca6
Loading
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -12,6 +12,7 @@ __pycache__/
*.crt
*.crt
*.zip
*.zip
*.srl
*.srl
*.log
services/nginx/certs/sign_req_body.json
services/nginx/certs/sign_req_body.json
services/easy_rsa/certs/pki
services/easy_rsa/certs/pki
services/easy_rsa/certs/*EasyRSA*
services/easy_rsa/certs/*EasyRSA*
@@ -35,4 +36,8 @@ docs/testing_with_postman/package-lock.json
results
results


helm/capif/*.lock
helm/capif/*.lock
<<<<<<< HEAD
helm/capif/charts
=======
helm/capif/charts/tempo*
helm/capif/charts/tempo*
>>>>>>> staging
+0 −13
Original line number Original line Diff line number Diff line
@@ -15,7 +15,6 @@ from ..core.publisher import Publisher
from functools import wraps
from functools import wraps


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




@@ -59,11 +58,6 @@ def onboarded_invokers_onboarding_id_delete(onboarding_id): # noqa: E501
    current_app.logger.info("Removing invoker")
    current_app.logger.info("Removing invoker")
    res = invoker_operations.remove_apiinvokerenrolmentdetail(onboarding_id)
    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
    return res


@cert_validation()
@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
        body = APIInvokerEnrolmentDetails.from_dict(connexion.request.get_json())  # noqa: E501
    res = invoker_operations.update_apiinvokerenrolmentdetail(onboarding_id,body)
    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
    return res




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


    current_app.logger.info("Creating Invoker")
    current_app.logger.info("Creating Invoker")
    res = invoker_operations.add_apiinvokerenrolmentdetail(body, username, uuid)
    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
    return res
+16 −3
Original line number Original line Diff line number Diff line
@@ -11,9 +11,10 @@ from .auth_manager import AuthManager
from .resources import Resource
from .resources import Resource
from ..config import Config
from ..config import Config
from api_invoker_management.models.api_invoker_enrolment_details import APIInvokerEnrolmentDetails
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):
class InvokerManagementOperations(Resource):


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


        res = make_response(object=apiinvokerenrolmentdetail, status=201)
        res = make_response(object=apiinvokerenrolmentdetail, status=201)
        res.headers['Location'] = "/api-invoker-management/v1/onboardedInvokers/" + str(api_invoker_id)
        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
        return res


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


            res = make_response(object=APIInvokerEnrolmentDetails().from_dict(dict_to_camel_case(result)), status=200)
            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
            return res


        except Exception as e:
        except Exception as e:
@@ -153,7 +161,12 @@ class InvokerManagementOperations(Resource):
            current_app.logger.debug("Invoker resource removed from database")
            current_app.logger.debug("Invoker resource removed from database")
            current_app.logger.debug("Netapp offboarded sucessfuly")
            current_app.logger.debug("Netapp offboarded sucessfuly")
            out =  "The Netapp matching onboardingId  " + onboard_id + " was offboarded."
            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:
        except Exception as e:
            exception = "An exception occurred in remove invoker"
            exception = "An exception occurred in remove invoker"
+41 −0
Original line number Original line 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
Original line number Original line 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.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)
            return make_response(object=out, status=204)


        except Exception as e:
        except Exception as e:
Loading