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
|
acquired = False
|
||||||
|
|
||||||
for domain in config.domains:
|
for domain in config.certificates:
|
||||||
# arguments passed to uacme
|
# arguments passed to uacme
|
||||||
uacme_domains = [domain]
|
uacme_domains = [domain]
|
||||||
if domain.startswith('*.'):
|
if domain.startswith('*.'):
|
||||||
|
|
|
@ -9,6 +9,7 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
post_acquire: list[str]
|
post_acquire: list[str]
|
||||||
|
certificates: list[str]
|
||||||
domains: dict[str, str]
|
domains: dict[str, str]
|
||||||
secrets: dict[str, str]
|
secrets: dict[str, str]
|
||||||
acme_path: str
|
acme_path: str
|
||||||
|
@ -17,13 +18,15 @@ class Config:
|
||||||
parts = domain.split('.')
|
parts = domain.split('.')
|
||||||
for i in range(len(parts)-1):
|
for i in range(len(parts)-1):
|
||||||
zone = '.'.join(parts[i:])
|
zone = '.'.join(parts[i:])
|
||||||
if '.'.join(parts[i:]) in self.domains:
|
if zone in self.domains:
|
||||||
return zone
|
return zone
|
||||||
log.error('could not find zone for domain %s', domain)
|
log.error('could not find zone for domain %s', domain)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def get_handler(self, domain: str) -> str:
|
def get_handler(self, domain: str) -> str:
|
||||||
|
if domain in self.domains:
|
||||||
return self.domains[domain]
|
return self.domains[domain]
|
||||||
|
raise Exception(f'domain {domain} not found in the config')
|
||||||
|
|
||||||
def get_secret(self, handler: str) -> str:
|
def get_secret(self, handler: str) -> str:
|
||||||
return self.secrets[handler]
|
return self.secrets[handler]
|
||||||
|
@ -38,7 +41,7 @@ def read_config(path: Optional[str]) -> Config:
|
||||||
raw_conf = tomllib.load(file)
|
raw_conf = tomllib.load(file)
|
||||||
|
|
||||||
for key in raw_conf:
|
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)
|
log.warning('unknown config key: %s', key)
|
||||||
|
|
||||||
c = Config()
|
c = Config()
|
||||||
|
@ -77,4 +80,13 @@ def read_config(path: Optional[str]) -> Config:
|
||||||
else:
|
else:
|
||||||
c.acme_path = '/var/www/acme/.well-known/acme-challenge'
|
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
|
return c
|
||||||
|
|
Loading…
Reference in a new issue