From 8d3471396f9c741ef079d30d8ffd276fc7eca5e7 Mon Sep 17 00:00:00 2001 From: Tal Date: Mon, 11 Nov 2024 17:42:24 +0200 Subject: [PATCH] fix: disable pusher when env variables are not set (#2434) --- keep/api/core/dependencies.py | 22 +++++++++++++++++----- pyproject.toml | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/keep/api/core/dependencies.py b/keep/api/core/dependencies.py index 21023f347..08779567a 100644 --- a/keep/api/core/dependencies.py +++ b/keep/api/core/dependencies.py @@ -11,6 +11,7 @@ # Just a fake random tenant id SINGLE_TENANT_UUID = "keep" SINGLE_TENANT_EMAIL = "admin@keephq" +PUSHER_DISABLED = os.environ.get("PUSHER_DISABLED", "false") == "true" async def extract_generic_body(request: Request) -> dict | bytes | FormData: @@ -36,20 +37,31 @@ async def extract_generic_body(request: Request) -> dict | bytes | FormData: def get_pusher_client() -> Pusher | None: - if os.environ.get("PUSHER_DISABLED", "false") == "true": + pusher_host = os.environ.get("PUSHER_HOST") + pusher_app_id = os.environ.get("PUSHER_APP_ID") + pusher_app_key = os.environ.get("PUSHER_APP_KEY") + pusher_app_secret = os.environ.get("PUSHER_APP_SECRET") + if ( + PUSHER_DISABLED + or pusher_host is None + or pusher_app_id is None + or pusher_app_key is None + or pusher_app_secret is None + ): + logger.debug("Pusher is disabled or missing environment variables") return None # TODO: defaults on open source no docker return Pusher( - host=os.environ.get("PUSHER_HOST"), + host=pusher_host, port=( int(os.environ.get("PUSHER_PORT")) if os.environ.get("PUSHER_PORT") else None ), - app_id=os.environ.get("PUSHER_APP_ID"), - key=os.environ.get("PUSHER_APP_KEY"), - secret=os.environ.get("PUSHER_APP_SECRET"), + app_id=pusher_app_id, + key=pusher_app_key, + secret=pusher_app_secret, ssl=False if os.environ.get("PUSHER_USE_SSL", False) is False else True, cluster=os.environ.get("PUSHER_CLUSTER"), ) diff --git a/pyproject.toml b/pyproject.toml index 3f4d99726..b688068a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "keep" -version = "0.28.4" +version = "0.28.5" description = "Alerting. for developers, by developers." authors = ["Keep Alerting LTD"] readme = "README.md"