Fix integration detection in certbot-auth and certbot-cleanup scripts + update gen ones to use the new get_integration utils function

This commit is contained in:
Théophile Diot 2024-03-13 09:07:04 +00:00
parent 8a3502f432
commit 64a0a17b20
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
5 changed files with 6 additions and 34 deletions

View file

@ -26,7 +26,6 @@ try:
integration = get_integration()
LOGGER.info(f"Detected {integration} integration")
LOGGER.info(f"Sending challenge {token} with validation {validation}")
# Cluster case
if integration in ("Docker", "Swarm", "Kubernetes", "Autoconf"):

View file

@ -25,7 +25,6 @@ try:
integration = get_integration()
LOGGER.info(f"Detected {integration} integration")
LOGGER.info(f"Cleaning up challenge {token}")
# Cluster case
if integration in ("Docker", "Swarm", "Kubernetes", "Autoconf"):
@ -34,7 +33,7 @@ try:
with lock:
instances = db.get_instances()
LOGGER.info(f"Sending challenge to {len(instances)} instances")
LOGGER.info(f"Cleaning challenge from {len(instances)} instances")
for instance in instances:
api = API(f"http://{instance['hostname']}:{instance['port']}", host=instance["server_name"])
sent, err, status, resp = api.request("DELETE", "/lets-encrypt/challenge", data={"token": token})

View file

@ -16,6 +16,7 @@ for deps_path in [join(sep, "usr", "share", "bunkerweb", *paths) for paths in ((
if deps_path not in sys_path:
sys_path.append(deps_path)
from common_utils import get_integration # type: ignore
from logger import setup_logger # type: ignore
from Configurator import Configurator
from Templator import Templator
@ -58,21 +59,7 @@ if __name__ == "__main__":
logger.info(f"Output : {output_path}")
logger.info(f"Target : {target_path}")
integration = "Linux"
integration_path = Path(sep, "usr", "share", "bunkerweb", "INTEGRATION")
os_release_path = Path(sep, "etc", "os-release")
if getenv("KUBERNETES_MODE", "no").lower() == "yes":
integration = "Kubernetes"
elif getenv("SWARM_MODE", "no").lower() == "yes":
integration = "Swarm"
elif getenv("AUTOCONF_MODE", "no").lower() == "yes":
integration = "Autoconf"
elif integration_path.is_file():
integration = integration_path.read_text().strip()
elif os_release_path.is_file() and "Alpine" in os_release_path.read_text():
integration = "Docker"
del integration_path, os_release_path
integration = get_integration()
if args.variables:
variables_path = Path(normpath(args.variables))

View file

@ -16,6 +16,7 @@ for deps_path in [join(sep, "usr", "share", "bunkerweb", *paths) for paths in ((
from docker import DockerClient
from common_utils import get_integration # type: ignore
from logger import setup_logger # type: ignore
from Database import Database # type: ignore
from Configurator import Configurator
@ -103,21 +104,7 @@ if __name__ == "__main__":
logger.info(f"Pro plugins : {pro_plugins_path}")
logger.info(f"Init : {args.init}")
integration = "Linux"
integration_path = Path(sep, "usr", "share", "bunkerweb", "INTEGRATION")
os_release_path = Path(sep, "etc", "os-release")
if getenv("KUBERNETES_MODE", "no").lower() == "yes":
integration = "Kubernetes"
elif getenv("SWARM_MODE", "no").lower() == "yes":
integration = "Swarm"
elif getenv("AUTOCONF_MODE", "no").lower() == "yes":
integration = "Autoconf"
elif integration_path.is_file():
integration = integration_path.read_text().strip()
elif os_release_path.is_file() and "Alpine" in os_release_path.read_text():
integration = "Docker"
del integration_path, os_release_path
integration = get_integration()
if args.init:
logger.info(f"Detected {integration} integration")

View file

@ -21,7 +21,7 @@ def get_integration() -> str:
elif getenv("AUTOCONF_MODE", "no").lower() == "yes":
return "Autoconf"
elif integration_path.is_file():
return integration_path.read_text(encoding="utf-8").strip().lower()
return integration_path.read_text(encoding="utf-8").strip().title()
elif os_release_path.is_file() and "Alpine" in os_release_path.read_text(encoding="utf-8"):
return "Docker"