cert_path_provider.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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")
  29. class GetSslCertPathProvider(CertPathProvider):
  30. def __init__(self, acme_dir: str):
  31. self._acme_dir = acme_dir
  32. def _join_paths(self, fqdn: str, file_name: str) -> ntpath:
  33. return os.path.join(self._acme_dir, fqdn, file_name)
  34. def provide_cert_path(self, fqdn: str) -> ntpath:
  35. self._join_paths(fqdn, fqdn + ".crt")
  36. def provide_fullchain_path(self, fqdn: str) -> ntpath:
  37. self._join_paths(fqdn, "fullchain.crt")
  38. def provide_key_path(self, fqdn: str) -> ntpath:
  39. self._join_paths(fqdn, fqdn + ".key")