cert_path_provider.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_fullchain_path(self, fqdn: str) -> ntpath:
  11. pass
  12. @abstractmethod
  13. def provide_key_path(self, fqdn: str) -> ntpath:
  14. pass
  15. class AcmeToolCertPathProvider(CertPathProvider):
  16. def __init__(self, acme_dir: str):
  17. self._acme_dir = acme_dir
  18. def provide_key_path(self, fqdn: str) -> ntpath:
  19. return self._join_paths(fqdn, "privkey")
  20. def _join_paths(self, fqdn: str, file_name: str) -> ntpath:
  21. return os.path.join(self._acme_dir, "live", fqdn, file_name)
  22. def provide_fullchain_path(self, fqdn: str) -> ntpath:
  23. return self._join_paths(fqdn, "fullchain")
  24. class GetSslCertPathProvider(CertPathProvider):
  25. def __init__(self, acme_dir: str):
  26. self._acme_dir = acme_dir
  27. def _join_paths(self, fqdn: str, file_name: str) -> ntpath:
  28. return os.path.join(self._acme_dir, fqdn, file_name)
  29. def provide_fullchain_path(self, fqdn: str) -> ntpath:
  30. return self._join_paths(fqdn, "fullchain.crt")
  31. def provide_key_path(self, fqdn: str) -> ntpath:
  32. return self._join_paths(fqdn, fqdn + ".key")