#!/usr/bin/env python3 # SPDX-FileCopyrightText: 2024 Matthew Fennell # # SPDX-License-Identifier: AGPL-3.0-only import logging import subprocess import tomllib def main() -> None: with open("config.toml", "rb") as config_file: full_config = tomllib.load(config_file) config = full_config["config"] domains = full_config["domains"] for domain in domains.values(): subdomain_list = domain["domains"] subdomain_requests = [ request for subdomain in subdomain_list for request in ("--domains", subdomain) ] command = ( [ "lego", "--accept-tos", "--email", domain["acme_email"], "--dns", "desec", "--server", config["acme_server"], "--dns.disable-cp", ] + subdomain_requests + ["renew", "--renew-hook", domain["renew_script"]] ) environment = { "DESEC_POLLING_INTERVAL": str(config["timeout_seconds"]), "DESEC_TOKEN": domain["desec_token"], } logging.info(f"Running command {command}") subprocess.run(command, env=environment) if __name__ == "__main__": main()