Browse Source

Implement additional cert path provider for getssl

Helmut Pozimski 11 months ago
parent
commit
a7307e5d49
2 changed files with 27 additions and 5 deletions
  1. 17 0
      amulib/cert_path_provider.py
  2. 10 5
      amulib/main.py

+ 17 - 0
amulib/cert_path_provider.py

@@ -38,3 +38,20 @@ class AcmeToolCertPathProvider(CertPathProvider):
 
     def provide_fullchain_path(self, fqdn: str) -> ntpath:
         return self._join_paths(fqdn, "fullchain")
+
+
+class GetSslCertPathProvider(CertPathProvider):
+    def __init__(self, acme_dir: str):
+        self._acme_dir = acme_dir
+
+    def _join_paths(self, fqdn: str, file_name: str) -> ntpath:
+        return os.path.join(self._acme_dir, fqdn, file_name)
+
+    def provide_cert_path(self, fqdn: str) -> ntpath:
+        self._join_paths(fqdn, fqdn + ".crt")
+
+    def provide_fullchain_path(self, fqdn: str) -> ntpath:
+        self._join_paths(fqdn, "fullchain.crt")
+
+    def provide_key_path(self, fqdn: str) -> ntpath:
+        self._join_paths(fqdn, fqdn + ".key")

+ 10 - 5
amulib/main.py

@@ -14,7 +14,7 @@ import logging
 import json
 import sys
 
-from amulib.cert_path_provider import AcmeToolCertPathProvider
+from amulib.cert_path_provider import AcmeToolCertPathProvider, GetSslCertPathProvider
 from amulib.helpers import get_log_level
 from amulib import apache
 from amulib import postfix
@@ -79,12 +79,17 @@ def set_log_level(args, config, logger):
 
 
 def create_cert_path_provider(cert_path_provider, config, logger):
-    if "acme_tool" in config and config["acme_tool"] == "acmetool":
-        cert_path_provider = AcmeToolCertPathProvider(config["acme_dir"])
+    if "acme_tool" in config:
+        if config["acme_tool"] == "acmetool":
+            return AcmeToolCertPathProvider(config["acme_dir"])
+        elif config["acme_tool"] == "getssl":
+            return GetSslCertPathProvider(config["acme_dir"])
+        else:
+            logger.error("Invalid acme tooling specified")
+            sys.exit(1)
     else:
-        logger.error("Invalid acme tooling specified")
+        logger.error("No acme tooling specified in configuration")
         sys.exit(1)
-    return cert_path_provider
 
 
 def execute_services(args, cert_path_provider, config):