fix: add config.certificates
This commit is contained in:
parent
429c10ab48
commit
77ed0c3e4b
2 changed files with 16 additions and 4 deletions
|
@ -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('*.'):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue