cert_path_provider.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # SPDX-FileCopyrightText: 2023 Helmut Pozimski <helmut@pozimski.eu>
  2. #
  3. # SPDX-License-Identifier: GPL-2.0-only
  4. import ntpath
  5. import os
  6. from abc import ABC, abstractmethod
  7. # -*- coding: utf8 -*-
  8. class CertPathProvider(ABC):
  9. @abstractmethod
  10. def provide_cert_path(self, fqdn: str) -> ntpath:
  11. pass
  12. @abstractmethod
  13. def provide_fullchain_path(self, fqdn: str) -> ntpath:
  14. pass
  15. @abstractmethod
  16. def provide_key_path(self, fqdn: str) -> ntpath:
  17. pass
  18. class AcmeToolCertPathProvider(CertPathProvider):
  19. def __init__(self, acme_dir: str):
  20. self._acme_dir = acme_dir
  21. def provide_key_path(self, fqdn: str) -> ntpath:
  22. return self._join_paths(fqdn, "privkey")
  23. def _join_paths(self, fqdn: str, file_name: str) -> ntpath:
  24. return os.path.join(self._acme_dir, "live", fqdn, file_name)
  25. def provide_cert_path(self, fqdn: str) -> ntpath:
  26. return self._join_paths(fqdn, "cert")
  27. def provide_fullchain_path(self, fqdn: str) -> ntpath:
  28. return self._join_paths(fqdn, "fullchain")