Esempio n. 1
0
    def test_publish_response(self):
        publisher = AuditLogPublisher()
        publisher.publish = MagicMock()

        msg = {'bogus': 'msg'}
        publisher.publish_response(msg)
        publisher.publish.assert_called_with('response', msg)
Esempio n. 2
0
class AuditLogger:
    logger = None

    @classmethod
    def get_instance(cls):
        if cls.logger is None:
            cls.logger = AuditLogger()

        return cls.logger

    def __init__(self):
        self.publisher = AuditLogPublisher()

    def _uuid(self):
        return str(uuid.uuid4())

    def log_request(self,
                    source: str,
                    destination: str,
                    extra_data: dict,
                    request_uuid: str = None):
        msg = {
            'type': 'request',
            'source': source,
            'destination': destination,
            'timestamp': datetime.datetime.now(),
            'request_uuid': request_uuid if request_uuid else self._uuid(),
            'data': extra_data,
        }
        self.publisher.publish_request(msg)

    def log_response(self,
                     source: str,
                     destination: str,
                     extra_data: dict,
                     request_uuid: str = None):
        msg = {
            'type': 'response',
            'source': source,
            'destination': destination,
            'timestamp': datetime.datetime.now(),
            'request_uuid': request_uuid if request_uuid else self._uuid(),
            'data': extra_data,
        }
        self.publisher.publish_response(msg)
Esempio n. 3
0
 def test_init(self):
     publisher = AuditLogPublisher()
     self.assertEqual(AUDIT_LOG_EXCHANGE, publisher._exchange)
Esempio n. 4
0
 def __init__(self):
     self.publisher = AuditLogPublisher()