lets encrypt - force regeneration of certs when switching environment (prod/staging)

This commit is contained in:
fl0ppy-d1sk 2024-09-16 15:08:17 +02:00
parent 274c1260d9
commit 1acef1f69d
2 changed files with 9 additions and 3 deletions

View file

@ -139,7 +139,7 @@ try:
for first_server, domains in domains_server_names.items():
generated_domains.update(domains.split(" "))
current_domains = search(rf"Domains: {first_server}(?P<domains>.*)$", stdout, MULTILINE)
current_domains = search(rf"Domains: {first_server}(?P<domains>.*)\n\s*Expiry Date: (?P<expiry_date>.*)$$", stdout, MULTILINE)
if not current_domains:
domains_to_ask[first_server] = False
continue
@ -147,6 +147,12 @@ try:
LOGGER.warning(f"Domains for {first_server} are not the same as in the certificate, asking new certificate...")
domains_to_ask[first_server] = True
continue
elif ("TEST_CERT" in current_domains.groupdict()['expiry_date'] and getenv(f"{first_server}_")):
LOGGER.warning(f"Certificate environment (staging/production) changed for {first_server}, asking new certificate...")
use_letsencrypt_staging = getenv(f"{first_server}_USE_LETS_ENCRYPT_STAGING", getenv("USE_LETS_ENCRYPT_STAGING", "no")) == "yes"
if ("TEST_CERT" in current_domains.groupdict()['expiry_date'] and not use_letsencrypt_staging) or ("TEST_CERT" not in current_domains.groupdict()['expiry_date'] and use_letsencrypt_staging):
LOGGER.warning(f"Certificate environment (staging/production) changed for {first_server}, asking new certificate...")
domains_to_ask[first_server] = True
LOGGER.info(f"Certificates already exists for domain(s) {domains}")
for first_server, domains in domains_server_names.items():

View file

@ -6,7 +6,7 @@ from datetime import datetime
from io import BytesIO
from itertools import chain
from json import load as json_load
from logging import FileHandler
from logging import FileHandler, Formatter
from os import _exit, environ, getenv, getpid, sep
from os.path import join
from pathlib import Path
@ -81,7 +81,7 @@ logger = setup_logger("Scheduler", getenv("LOG_LEVEL", "INFO"))
if environ.get("LOG_TO_FILE", "no") == "yes":
file_handler = FileHandler("/var/log/bunkerweb/scheduler.log")
file_handler.setFormatter("%(asctime)s [%(name)s] [%(process)d] [%(levelname)s] - %(message)s")
file_handler.setFormatter(Formatter("%(asctime)s [%(name)s] [%(process)d] [%(levelname)s] - %(message)s"))
logger.addHandler(file_handler)
SLAVE_MODE = environ.get("SLAVE_MODE", "no") == "yes"