From e37e6c346048c11dae5056ae038b52b46042e51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Fri, 10 Mar 2023 13:16:27 +0100 Subject: [PATCH] Fix mixup of swarm and kubernetes when reading env variables + refactoring --- src/common/core/letsencrypt/jobs/certbot-auth.py | 4 ++-- src/common/core/letsencrypt/jobs/certbot-cleanup.py | 4 ++-- src/common/core/letsencrypt/jobs/certbot-deploy.py | 4 ++-- src/common/helpers/utils.sh | 2 +- src/common/utils/ApiCaller.py | 3 ++- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/common/core/letsencrypt/jobs/certbot-auth.py b/src/common/core/letsencrypt/jobs/certbot-auth.py index 97da4b8f8..8845740a7 100755 --- a/src/common/core/letsencrypt/jobs/certbot-auth.py +++ b/src/common/core/letsencrypt/jobs/certbot-auth.py @@ -31,9 +31,9 @@ try: # Get env vars bw_integration = None if getenv("KUBERNETES_MODE") == "yes": - bw_integration = "Swarm" - elif getenv("SWARM_MODE") == "yes": bw_integration = "Kubernetes" + elif getenv("SWARM_MODE") == "yes": + bw_integration = "Swarm" elif getenv("AUTOCONF_MODE") == "yes": bw_integration = "Autoconf" elif Path("/usr/share/bunkerweb/INTEGRATION").exists(): diff --git a/src/common/core/letsencrypt/jobs/certbot-cleanup.py b/src/common/core/letsencrypt/jobs/certbot-cleanup.py index 6f2fae3cd..0db6d9a78 100755 --- a/src/common/core/letsencrypt/jobs/certbot-cleanup.py +++ b/src/common/core/letsencrypt/jobs/certbot-cleanup.py @@ -32,9 +32,9 @@ try: # Get env vars bw_integration = None if getenv("KUBERNETES_MODE") == "yes": - bw_integration = "Swarm" - elif getenv("SWARM_MODE") == "yes": bw_integration = "Kubernetes" + elif getenv("SWARM_MODE") == "yes": + bw_integration = "Swarm" elif getenv("AUTOCONF_MODE") == "yes": bw_integration = "Autoconf" elif Path("/usr/share/bunkerweb/INTEGRATION").exists(): diff --git a/src/common/core/letsencrypt/jobs/certbot-deploy.py b/src/common/core/letsencrypt/jobs/certbot-deploy.py index 0ec020352..9773e64fc 100755 --- a/src/common/core/letsencrypt/jobs/certbot-deploy.py +++ b/src/common/core/letsencrypt/jobs/certbot-deploy.py @@ -36,9 +36,9 @@ try: # Get env vars bw_integration = None if getenv("KUBERNETES_MODE") == "yes": - bw_integration = "Swarm" - elif getenv("SWARM_MODE") == "yes": bw_integration = "Kubernetes" + elif getenv("SWARM_MODE") == "yes": + bw_integration = "Swarm" elif getenv("AUTOCONF_MODE") == "yes": bw_integration = "Autoconf" elif Path("/usr/share/bunkerweb/INTEGRATION").exists(): diff --git a/src/common/helpers/utils.sh b/src/common/helpers/utils.sh index 7b53961f5..80beb6af3 100644 --- a/src/common/helpers/utils.sh +++ b/src/common/helpers/utils.sh @@ -48,7 +48,7 @@ function log() { category="$1" severity="$2" message="$3" - echo "$when $category - $severity - $message" + echo "$when - $category - $severity - $message" } # get only interesting env (var=value) diff --git a/src/common/utils/ApiCaller.py b/src/common/utils/ApiCaller.py index 8dce5d7af..a4e1ca5c5 100644 --- a/src/common/utils/ApiCaller.py +++ b/src/common/utils/ApiCaller.py @@ -3,6 +3,7 @@ from os import environ, getenv from os.path import sep from sys import path as sys_path from tarfile import open as taropen +from typing import Optional if "/usr/share/bunkerweb/utils" not in sys_path: sys_path.append("/usr/share/bunkerweb/utils") @@ -22,7 +23,7 @@ class ApiCaller: self.__apis = apis self.__logger = setup_logger("Api", environ.get("LOG_LEVEL", "INFO")) - def auto_setup(self, bw_integration: str = None): + def auto_setup(self, bw_integration: Optional[str] = None): if bw_integration is None: if getenv("KUBERNETES_MODE", "no") == "yes": bw_integration = "Kubernetes"