mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 00:48:32 +01:00
d0ba7675f0
* chore: change max_retries to 10 * chore: only send custom domain deleted event if it is not a partner domain * chore: newrelic events metric names rename * chore: emit failed events metric * chore: migration for contact.flags and custom_domain.pending_deletion * chore: mark custom_domain as pending_deletion when deleting it * chore: add event type to metric
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import requests
|
|
import newrelic.agent
|
|
|
|
from abc import ABC, abstractmethod
|
|
from app.config import EVENT_WEBHOOK, EVENT_WEBHOOK_SKIP_VERIFY_SSL
|
|
from app.log import LOG
|
|
from app.models import SyncEvent
|
|
|
|
|
|
class EventSink(ABC):
|
|
@abstractmethod
|
|
def process(self, event: SyncEvent) -> bool:
|
|
pass
|
|
|
|
|
|
class HttpEventSink(EventSink):
|
|
def process(self, event: SyncEvent) -> bool:
|
|
if not EVENT_WEBHOOK:
|
|
LOG.warning("Skipping sending event because there is no webhook configured")
|
|
return False
|
|
|
|
LOG.info(f"Sending event {event.id} to {EVENT_WEBHOOK}")
|
|
|
|
res = requests.post(
|
|
url=EVENT_WEBHOOK,
|
|
data=event.content,
|
|
headers={"Content-Type": "application/x-protobuf"},
|
|
verify=not EVENT_WEBHOOK_SKIP_VERIFY_SSL,
|
|
)
|
|
newrelic.agent.record_custom_event(
|
|
"EventSentToPartner", {"http_code": res.status_code}
|
|
)
|
|
if res.status_code != 200:
|
|
LOG.warning(
|
|
f"Failed to send event to webhook: {res.status_code} {res.text}"
|
|
)
|
|
return False
|
|
else:
|
|
LOG.info(f"Event {event.id} sent successfully to webhook")
|
|
return True
|
|
|
|
|
|
class ConsoleEventSink(EventSink):
|
|
def process(self, event: SyncEvent) -> bool:
|
|
LOG.info(f"Handling event {event.id}")
|
|
return True
|