|
11 | 11 |
|
12 | 12 | from chatmaild.config import read_config |
13 | 13 | from pyinfra import facts, host, logger |
14 | | -from pyinfra.facts import hardware |
15 | 14 | from pyinfra.api import FactBase |
| 15 | +from pyinfra.facts import hardware |
16 | 16 | from pyinfra.facts.files import Sha256File |
17 | 17 | from pyinfra.facts.systemd import SystemdEnabled |
18 | 18 | from pyinfra.operations import apt, files, pip, server, systemd |
19 | 19 |
|
20 | 20 | from cmdeploy.cmdeploy import Out |
21 | 21 |
|
22 | 22 | from .acmetool import AcmetoolDeployer |
23 | | -from .selfsigned.deployer import SelfSignedTlsDeployer |
24 | 23 | from .basedeploy import ( |
25 | 24 | Deployer, |
26 | 25 | Deployment, |
|
30 | 29 | has_systemd, |
31 | 30 | ) |
32 | 31 | from .dovecot.deployer import DovecotDeployer |
| 32 | +from .external.deployer import ExternalTlsDeployer |
33 | 33 | from .filtermail.deployer import FiltermailDeployer |
34 | 34 | from .mtail.deployer import MtailDeployer |
35 | 35 | from .nginx.deployer import NginxDeployer |
36 | 36 | from .opendkim.deployer import OpendkimDeployer |
37 | 37 | from .postfix.deployer import PostfixDeployer |
| 38 | +from .selfsigned.deployer import SelfSignedTlsDeployer |
38 | 39 | from .www import build_webpages, find_merge_conflict, get_paths |
39 | 40 |
|
40 | 41 |
|
@@ -540,6 +541,20 @@ def activate(self): |
540 | 541 | ) |
541 | 542 |
|
542 | 543 |
|
| 544 | +def get_tls_deployer(config, mail_domain): |
| 545 | + """Select the appropriate TLS deployer based on config.""" |
| 546 | + tls_domains = [mail_domain, f"mta-sts.{mail_domain}", f"www.{mail_domain}"] |
| 547 | + |
| 548 | + if config.tls_cert_mode == "acme": |
| 549 | + return AcmetoolDeployer(config.acme_email, tls_domains) |
| 550 | + elif config.tls_cert_mode == "self": |
| 551 | + return SelfSignedTlsDeployer(mail_domain) |
| 552 | + elif config.tls_cert_mode == "external": |
| 553 | + return ExternalTlsDeployer(config.tls_cert_path, config.tls_key_path) |
| 554 | + else: |
| 555 | + raise ValueError(f"Unknown tls_cert_mode: {config.tls_cert_mode}") |
| 556 | + |
| 557 | + |
543 | 558 | def deploy_chatmail(config_path: Path, disable_mail: bool, website_only: bool) -> None: |
544 | 559 | """Deploy a chat-mail instance. |
545 | 560 |
|
@@ -608,12 +623,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool, website_only: bool) - |
608 | 623 | ) |
609 | 624 | exit(1) |
610 | 625 |
|
611 | | - tls_domains = [mail_domain, f"mta-sts.{mail_domain}", f"www.{mail_domain}"] |
612 | | - |
613 | | - if config.tls_cert_mode == "acme": |
614 | | - tls_deployer = AcmetoolDeployer(config.acme_email, tls_domains) |
615 | | - else: |
616 | | - tls_deployer = SelfSignedTlsDeployer(mail_domain) |
| 626 | + tls_deployer = get_tls_deployer(config, mail_domain) |
617 | 627 |
|
618 | 628 | all_deployers = [ |
619 | 629 | ChatmailDeployer(mail_domain), |
|
0 commit comments