Commit 25540b00 authored by Jorge Moratinos's avatar Jorge Moratinos
Browse files

SERVICE_API_AVAILABLE and UNAVAILABLE implemented, also the test related

parent a90c0d50
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -103,7 +103,8 @@ class LoggingInvocationOperations(Resource):

                    current_app.logger.info(event)
                    invocation_log_base['logs']=[log]
                    RedisEvent(event,invocation_log_base,"invocationLogs").send_event()
                    invocationLogs=[invocation_log_base]
                    RedisEvent(event,"invocationLogs",invocationLogs).send_event()

            current_app.logger.debug("After log check")

+26 −8
Original line number Diff line number Diff line
@@ -4,8 +4,26 @@ import json

publisher_ops = Publisher()


class RedisEvent():
    def __init__(self, event, information, event_detail_key) -> None:
    def __init__(self, event, event_detail_key, information) -> 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,
            "key": event_detail_key,
+4 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ from cryptography.hazmat.backends import default_backend
from ..core.validate_user import ControlAccess
from functools import wraps
import pymongo
from ..core.redis_event import RedisEvent


service_operations = PublishServiceOperations()
@@ -84,7 +85,8 @@ def apf_id_service_apis_post(apf_id, body): # noqa: E501

    if res.status_code == 201:
        current_app.logger.info("Service published")
        publisher_ops.publish_message("events", "SERVICE_API_AVAILABLE")
        api_id=res.headers['Location'].split('/')[-1]
        RedisEvent("SERVICE_API_AVAILABLE", "apiIds", [api_id] ).send_event()

    return res

@@ -107,7 +109,7 @@ def apf_id_service_apis_service_api_id_delete(service_api_id, apf_id): # noqa:

    if res.status_code == 204:
        current_app.logger.info("Removed service published")
        publisher_ops.publish_message("events", "SERVICE_API_UNAVAILABLE")
        RedisEvent("SERVICE_API_UNAVAILABLE", "apiIds", [service_api_id] ).send_event()
        publisher_ops.publish_message("internal-messages", f"service-removed:{service_api_id}")

    return res
+40 −0
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, information) -> 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,
            "key": event_detail_key,
            "information": information
        }

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

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

    def __call__(self):
        return self.redis_event
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ CAPIF_VAULT_PORT=8200
# CAPIF_VAULT_TOKEN=dev-only-token
CAPIF_VAULT_TOKEN=read-ca-token

MOCK_SERVER_URL=http://192.168.0.14:9090
MOCK_SERVER_URL=http://10.95.115.22:9090


echo "CAPIF_HOSTNAME = $CAPIF_HOSTNAME"
Loading