postfix.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # SPDX-FileCopyrightText: 2016-2023 Helmut Pozimski <helmut@pozimski.eu>
  2. #
  3. # SPDX-License-Identifier: GPL-2.0-only
  4. # -*- coding: utf8 -*-
  5. """ Contains the postfix module which manages certificates for the postfix
  6. mail server.
  7. """
  8. import socket
  9. from amulib import service
  10. from amulib.cert_path_provider import CertPathProvider
  11. def run(cert_path_provider: CertPathProvider, config=None,
  12. named_key_path="/run/named/session.key",
  13. dns_server="localhost"):
  14. """ manages the certificates for postfix
  15. :param cert_path_provider: provider for certificate paths
  16. :type cert_path_provider: CertPathProvider
  17. :param config: configuration for the service
  18. :type config: dict
  19. :param acme_dir: path to the acme state dir
  20. :type acme_dir: str
  21. :param named_key_path: path to the named session.key
  22. :type named_key_path: str
  23. :param dns_server: DNS server to use to create TLSA records
  24. :type dns_server: str
  25. """
  26. hostname = socket.gethostname()
  27. if not config:
  28. config = {
  29. "certificate_path": "/etc/postfix/%s.crt" % hostname,
  30. "key_path": "/etc/postfix/%s.key" % hostname,
  31. "tlsa": True,
  32. "tlsa_ports": [25, 465, 587]
  33. }
  34. service.run(cert_path_provider, "postfix", config, named_key_path, dns_server)