fix: add config.certificates
This commit is contained in:
parent
429c10ab48
commit
5561b8f7a2
3 changed files with 17 additions and 5 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:
|
||||
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
|
||||
|
|
|
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||
|
||||
[project]
|
||||
name = "nyacme"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
authors = [
|
||||
{name = "Patrycja Rosa", email = "python@ptrcnull.me"},
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue