From 77ed0c3e4bb40555cb98ac7766a98e26bf17eb03 Mon Sep 17 00:00:00 2001 From: ptrcnull Date: Sat, 16 Mar 2024 19:36:38 +0100 Subject: [PATCH] fix: add config.certificates --- nyacme/__main__.py | 2 +- nyacme/config.py | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/nyacme/__main__.py b/nyacme/__main__.py index 29ab526..53743d7 100644 --- a/nyacme/__main__.py +++ b/nyacme/__main__.py @@ -24,7 +24,7 @@ def main() -> None: acquired = False - for domain in config.domains: + for domain in config.certificates: # arguments passed to uacme uacme_domains = [domain] if domain.startswith('*.'): diff --git a/nyacme/config.py b/nyacme/config.py index 7043cdd..0848982 100644 --- a/nyacme/config.py +++ b/nyacme/config.py @@ -9,6 +9,7 @@ log = logging.getLogger(__name__) class Config: post_acquire: list[str] + certificates: list[str] domains: dict[str, str] secrets: dict[str, str] acme_path: str @@ -17,13 +18,15 @@ class Config: parts = domain.split('.') for i in range(len(parts)-1): zone = '.'.join(parts[i:]) - if '.'.join(parts[i:]) in self.domains: + if zone in self.domains: return zone log.error('could not find zone for domain %s', domain) sys.exit(1) def get_handler(self, domain: str) -> str: - return self.domains[domain] + if domain in self.domains: + return self.domains[domain] + raise Exception(f'domain {domain} not found in the config') def get_secret(self, handler: str) -> str: return self.secrets[handler] @@ -38,7 +41,7 @@ def read_config(path: Optional[str]) -> Config: raw_conf = tomllib.load(file) for key in raw_conf: - if key not in ('domains', 'secrets', 'post_acquire', 'acme_path'): + if key not in ('domains', 'secrets', 'post_acquire', 'acme_path', 'certificates'): log.warning('unknown config key: %s', key) c = Config() @@ -77,4 +80,13 @@ def read_config(path: Optional[str]) -> Config: else: c.acme_path = '/var/www/acme/.well-known/acme-challenge' + if 'certificates' not in raw_conf: + log.error('missing "certificates"') + sys.exit(1) + + c.certificates = [] + for cert in raw_conf['certificates']: + assert isinstance(cert, str), 'certificate should be a string' + c.certificates.append(cert) + return c