Skip to content

Commit

Permalink
chore: Refactor check_cert function to handle exceptions and improve …
Browse files Browse the repository at this point in the history
…error logging
  • Loading branch information
TheophileDiot committed Jun 12, 2024
1 parent 7ab6c86 commit b56606b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/common/core/customcert/jobs/custom-cert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from contextlib import suppress
from os import getenv, sep
from os.path import join
from pathlib import Path
Expand All @@ -21,8 +20,8 @@
JOB = Job(LOGGER)


def check_cert(cert_file: Union[Path, bytes], key_file: Union[Path, bytes], first_server: str) -> Tuple[bool, str]:
with suppress(BaseException):
def check_cert(cert_file: Union[Path, bytes], key_file: Union[Path, bytes], first_server: str) -> Tuple[bool, Union[str, BaseException]]:
try:
ret = False
if not cert_file or not key_file:
return False, "Both variables CUSTOM_SSL_CERT and CUSTOM_SSL_KEY have to be set to use custom certificates"
Expand Down Expand Up @@ -54,7 +53,8 @@ def check_cert(cert_file: Union[Path, bytes], key_file: Union[Path, bytes], firs
LOGGER.error(f"Error while caching custom-key key.pem file : {err}")

return ret, ""
return False, "exception"
except BaseException as e:
return False, e


status = 0
Expand Down Expand Up @@ -112,8 +112,8 @@ def check_cert(cert_file: Union[Path, bytes], key_file: Union[Path, bytes], firs

LOGGER.info(f"Checking certificate for {first_server} ...")
need_reload, err = check_cert(cert_file, key_file, first_server)
if err == "exception":
LOGGER.exception(f"Exception while checking {first_server}'s certificate, skipping ...")
if isinstance(err, BaseException):
LOGGER.error(f"Exception while checking {first_server}'s certificate, skipping ... \n{err}")
skipped_servers.append(first_server)
continue
elif err:
Expand Down

0 comments on commit b56606b

Please sign in to comment.