Compare commits

...

2 Commits

Author SHA1 Message Date
László Károlyi 98a49b788a
More certbot_emu logic fixing 2024-04-09 22:55:03 +02:00
László Károlyi 8c92f19cc1
More refined logging 2024-04-09 22:38:58 +02:00
1 changed files with 13 additions and 12 deletions

View File

@ -1,4 +1,4 @@
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone
from functools import cached_property
from logging import getLogger
from os.path import normpath
@ -162,13 +162,12 @@ class _CertbotLogicEmulator(object):
:returns: The list of deployed cert's domains.
"""
config = self.cert.cli_config
config.certname = self.cert.lineagename
pre_hook(config=config)
self.cert.set_upcoming_as_latest()
renew_hook(
config=config, domains=self.cert.common_names,
lineage_path=self.cert.live_dir)
post_hook(config=config, renewed_domains=self.cert.common_names)
if config:
return []
if not self._installer:
return []
# In case of a newly-put-in-place certificate, reload server to
@ -176,7 +175,7 @@ class _CertbotLogicEmulator(object):
run_renewal_deployer(
config=config, lineage=self.cert, installer=self._installer)
notify(msg=(
f'Reloading {config.installer} server after certificate renewal'))
f'Reloading {self._installer} server after certificate renewal'))
self._installer.restart()
return self.cert.common_names
@ -217,16 +216,15 @@ class RenewHandler(HandlerBase):
if cert_config.max_ttl == 0:
cert_config.max_ttl = self._config.defaults.tlsa.ttl
utcnow = datetime.now(tz=timezone.utc).timestamp()
if cert.latest_upcoming_mtime + cert_config.max_ttl > utcnow:
delta = cert.latest_upcoming_mtime + cert_config.max_ttl - utcnow
tdelta = timedelta(seconds=delta)
if delta > 0:
# No putting in place necessary yet
notify(msg=(
'Certificate available in upcoming directory, waiting for TTL '
f'expiration ({cert_config.max_ttl} seconds).'))
f'expiration ({tdelta} remaining).'))
return []
notify(msg='TTL expired: moving upcoming certificates in place.')
pre_hook(config=cert.cli_config)
cert.set_upcoming_as_latest()
certbot_emu = _CertbotLogicEmulator(cert=cert, plugins=self._plugins)
return certbot_emu.run_installer_logic()
@ -264,17 +262,20 @@ class RenewHandler(HandlerBase):
renewed_domains = list[str]()
failed_domains = list[str]()
for certconfig_path, cert in to_renew.items():
notify(msg=(
f'\n===== Daneupdate renewal: Checking {certconfig_path}'))
notify(msg=f'===== Daneupdate renewal: Checking {certconfig_path}')
if certconfig_path in self.all_certs.already_adopted:
renewed_domains.extend(self._renew_one_adopted(
certconfig_path=certconfig_path, cert=cert))
# Add empty line
notify(msg='')
continue
certbot_emu = _CertbotLogicEmulator(
cert=cert, plugins=self._plugins)
renewed, failed = certbot_emu.run_renew_nonadopted_logic()
renewed_domains.extend(renewed)
failed_domains.extend(failed)
# Add empty line
notify(msg='')
run_saved_post_hooks(
renewed_domains=renewed_domains, failed_domains=failed_domains)
return 0