diff --git a/nyacme/config.py b/nyacme/config.py index 023dd00..ced6206 100644 --- a/nyacme/config.py +++ b/nyacme/config.py @@ -2,6 +2,7 @@ import logging import os import sys from typing import Any, Optional +from pathlib import Path import tomllib @@ -13,7 +14,7 @@ class Config: certificates: list[str] domains: dict[str, str] secrets: dict[str, str] - acme_path: str + acme_path: Path def find_zone(self, domain: str) -> str: parts = domain.split('.') @@ -74,9 +75,9 @@ def read_config(path: Optional[str]) -> Config: c.post_acquire = post_acquire if 'acme_path' in raw_conf: - c.acme_path = raw_conf['acme_path'] + c.acme_path = Path(raw_conf['acme_path']) else: - c.acme_path = '/var/www/acme/.well-known/acme-challenge' + c.acme_path = Path('/var/www/acme/.well-known/acme-challenge') if 'certificates' not in raw_conf: log.error('missing "certificates"') diff --git a/nyacme/handlers/http.py b/nyacme/handlers/http.py index 5c505ce..a5920b5 100644 --- a/nyacme/handlers/http.py +++ b/nyacme/handlers/http.py @@ -1,5 +1,3 @@ -import os - from ..config import Config from .base import Handler @@ -7,12 +5,11 @@ from .base import Handler class HTTPHandler(Handler): def __init__(self, zone: str, config: Config, token: str) -> None: super().__init__(zone, config, token) - self.filepath = os.path.join(config.acme_path, token) + self.filepath = config.acme_path / token - def create(self, record_name: str, record_value: str) -> None: - with open(self.filepath, 'w') as f: + def create(self, _: str, record_value: str) -> None: + with self.filepath.open('w') as f: f.write(record_value) - def remove(self, record_name: str) -> None: - if os.path.isfile(self.filepath): - os.unlink(self.filepath) + def remove(self, _: str) -> None: + self.filepath.unlink(missing_ok=True)