Skip to content

Commit

Permalink
chore: add config for enabling sync for specific users (#2184)
Browse files Browse the repository at this point in the history
* chore: add config for enabling sync for users

* chore: error handling
  • Loading branch information
cquintana92 authored Aug 19, 2024
1 parent d5869b8 commit a72b7bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import socket
import string
from ast import literal_eval
from typing import Callable, List
from typing import Callable, List, Optional
from urllib.parse import urlparse

from dotenv import load_dotenv
Expand Down Expand Up @@ -588,3 +588,20 @@ def getRateLimitFromConfig(
# We want it disabled by default, so only skip if defined
EVENT_WEBHOOK_SKIP_VERIFY_SSL = "EVENT_WEBHOOK_SKIP_VERIFY_SSL" in os.environ
EVENT_WEBHOOK_DISABLE = "EVENT_WEBHOOK_DISABLE" in os.environ


def read_webhook_enabled_user_ids() -> Optional[List[int]]:
user_ids = os.environ.get("EVENT_WEBHOOK_ENABLED_USER_IDS", None)
if user_ids is None:
return None

ids = []
for id in user_ids.split(","):
try:
ids.append(int(id.strip()))
except ValueError:
pass
return ids


EVENT_WEBHOOK_ENABLED_USER_IDS: Optional[List[int]] = read_webhook_enabled_user_ids()
4 changes: 4 additions & 0 deletions app/events/event_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def send_event(
if not config.EVENT_WEBHOOK and skip_if_webhook_missing:
return

if config.EVENT_WEBHOOK_ENABLED_USER_IDS is not None:
if user.id not in config.EVENT_WEBHOOK_ENABLED_USER_IDS:
return

partner_user = EventDispatcher.__partner_user(user.id)
if not partner_user:
return
Expand Down

0 comments on commit a72b7bd

Please sign in to comment.