feat: cert_manager detect file change
This commit is contained in:
@@ -17,6 +17,7 @@ class CertManager:
|
||||
__slots__ = [
|
||||
"certbot_conf",
|
||||
"certbot_www",
|
||||
"last_file_change",
|
||||
"logger",
|
||||
"self_signed_path",
|
||||
"with_certbot",
|
||||
@@ -32,6 +33,7 @@ class CertManager:
|
||||
self.certbot_www: pathlib.Path = pathlib.Path(params.certbot_www)
|
||||
self.self_signed_path: pathlib.Path = pathlib.Path(params.self_signed_path)
|
||||
self.with_certbot: bool = params.with_certbot
|
||||
self.last_file_change: int | float = 0
|
||||
|
||||
def init(self, hosts: list[str]) -> None:
|
||||
self.logger.debug("Initializing...")
|
||||
@@ -187,6 +189,7 @@ class CertManager:
|
||||
return None
|
||||
cert_file = self.get_cert(default_host)
|
||||
key_file = self.get_key(default_host)
|
||||
self.last_file_change = cert_file.stat().st_mtime
|
||||
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
||||
context.load_cert_chain(
|
||||
cert_file,
|
||||
@@ -195,6 +198,13 @@ class CertManager:
|
||||
context.sni_callback = self.__sni_callback
|
||||
return context
|
||||
|
||||
def detect_default_cert_change(self, default_host: str) -> bool:
|
||||
cert_file = self.get_cert(default_host)
|
||||
if cert_file.exists() and cert_file.stat().st_mtime != self.last_file_change:
|
||||
self.logger.debug("Detected change: %s", cert_file)
|
||||
return True
|
||||
return False
|
||||
|
||||
def __sni_callback(
|
||||
self, socket: ssl.SSLObject, host: str | None, _: ssl.SSLContext, /
|
||||
) -> None | int:
|
||||
|
||||
Reference in New Issue
Block a user