Skip to content

Commit

Permalink
chore: Fix error handling in custom-cert.py
Browse files Browse the repository at this point in the history
  • Loading branch information
TheophileDiot committed Aug 19, 2024
1 parent 13204be commit b1ce5cd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/common/core/customcert/jobs/custom-cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def check_cert(cert_file: Union[Path, bytes], key_file: Union[Path, bytes], firs
cached, err = JOB.cache_file("cert.pem", cert_file, service_id=first_server, checksum=cert_hash, delete_file=False)
if not cached:
LOGGER.error(f"Error while caching custom-cert cert.pem file : {err}")
return False, err

key_hash = bytes_hash(key_file)
old_hash = JOB.cache_hash("key.pem", service_id=first_server)
Expand All @@ -51,6 +52,7 @@ def check_cert(cert_file: Union[Path, bytes], key_file: Union[Path, bytes], firs
cached, err = JOB.cache_file("key.pem", key_file, service_id=first_server, checksum=key_hash, delete_file=False)
if not cached:
LOGGER.error(f"Error while caching custom-key key.pem file : {err}")
return False, err

return ret, ""
except BaseException as e:
Expand Down Expand Up @@ -98,6 +100,7 @@ def check_cert(cert_file: Union[Path, bytes], key_file: Union[Path, bytes], firs
except BaseException:
LOGGER.exception(f"Error while decoding cert data, skipping server {first_server}...")
skipped_servers.append(first_server)
status = 2
continue

if key_file:
Expand All @@ -108,17 +111,20 @@ def check_cert(cert_file: Union[Path, bytes], key_file: Union[Path, bytes], firs
except BaseException:
LOGGER.exception(f"Error while decoding key data, skipping server {first_server}...")
skipped_servers.append(first_server)
status = 2
continue

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

0 comments on commit b1ce5cd

Please sign in to comment.