mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 21:08:03 +00:00
cleanup dead code, clarify others
This commit is contained in:
@@ -200,13 +200,6 @@ def is_valid_ipv4(address: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def format_arpa_address(address: str) -> str:
|
|
||||||
if is_valid_ipv4(address):
|
|
||||||
return ipaddress.IPv4Address(address).reverse_pointer
|
|
||||||
DomainValidator().validate_domain_re(address)
|
|
||||||
return address
|
|
||||||
|
|
||||||
|
|
||||||
def format_mail_domain(raw_domain: str) -> str:
|
def format_mail_domain(raw_domain: str) -> str:
|
||||||
if is_valid_ipv4(raw_domain):
|
if is_valid_ipv4(raw_domain):
|
||||||
return f"[{raw_domain}]"
|
return f"[{raw_domain}]"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ from contextlib import nullcontext as does_not_raise
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from chatmaild.config import (
|
from chatmaild.config import (
|
||||||
format_arpa_address,
|
|
||||||
format_mail_domain,
|
format_mail_domain,
|
||||||
is_valid_ipv4,
|
is_valid_ipv4,
|
||||||
parse_size_mb,
|
parse_size_mb,
|
||||||
@@ -165,20 +164,6 @@ def test_is_valid_ipv4(input, result):
|
|||||||
assert result == is_valid_ipv4(input)
|
assert result == is_valid_ipv4(input)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
["input", "result", "exception"],
|
|
||||||
[
|
|
||||||
("example.org", "example.org", does_not_raise()),
|
|
||||||
("1.3.3.7", "7.3.3.1.in-addr.arpa", does_not_raise()),
|
|
||||||
("fe::1", None, pytest.raises(ValueError)),
|
|
||||||
("12394142", None, pytest.raises(ValueError)),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_format_arpa_address(input, result, exception):
|
|
||||||
with exception:
|
|
||||||
assert result == format_arpa_address(input)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
["input", "result", "exception"],
|
["input", "result", "exception"],
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -540,7 +540,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool, website_only: bool) -
|
|||||||
WebsiteDeployer(config),
|
WebsiteDeployer(config),
|
||||||
ChatmailVenvDeployer(config),
|
ChatmailVenvDeployer(config),
|
||||||
MtastsDeployer(),
|
MtastsDeployer(),
|
||||||
OpendkimDeployer(config.mail_domain),
|
*([] if config.ipv4_relay else [OpendkimDeployer(bare_host)]),
|
||||||
# Dovecot should be started before Postfix
|
# Dovecot should be started before Postfix
|
||||||
# because it creates authentication socket
|
# because it creates authentication socket
|
||||||
# required by Postfix.
|
# required by Postfix.
|
||||||
|
|||||||
7
cmdeploy/src/cmdeploy/external/deployer.py
vendored
7
cmdeploy/src/cmdeploy/external/deployer.py
vendored
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
from pyinfra import host
|
from pyinfra import host
|
||||||
from pyinfra.facts.files import File
|
from pyinfra.facts.files import File
|
||||||
|
|
||||||
@@ -21,8 +20,8 @@ class ExternalTlsDeployer(Deployer):
|
|||||||
def configure(self):
|
def configure(self):
|
||||||
# Verify cert and key exist on the remote host using pyinfra facts.
|
# Verify cert and key exist on the remote host using pyinfra facts.
|
||||||
for path in (self.cert_path, self.key_path):
|
for path in (self.cert_path, self.key_path):
|
||||||
if host.get_fact(File, path=path) is None:
|
if host.get_fact(File, path=path) is None:
|
||||||
raise Exception(f"External TLS file not found on server: {path}")
|
raise Exception(f"External TLS file not found on server: {path}")
|
||||||
|
|
||||||
self.ensure_systemd_unit(
|
self.ensure_systemd_unit(
|
||||||
"external/tls-cert-reload.path.j2",
|
"external/tls-cert-reload.path.j2",
|
||||||
@@ -40,5 +39,3 @@ class ExternalTlsDeployer(Deployer):
|
|||||||
running=True,
|
running=True,
|
||||||
enabled=True,
|
enabled=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import subprocess
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from chatmaild.config import is_valid_ipv4
|
||||||
|
|
||||||
from cmdeploy import remote
|
from cmdeploy import remote
|
||||||
from cmdeploy.cmdeploy import get_sshexec
|
from cmdeploy.cmdeploy import get_sshexec
|
||||||
from chatmaild.config import is_valid_ipv4
|
|
||||||
|
|
||||||
|
|
||||||
class TestSSHExecutor:
|
class TestSSHExecutor:
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import imaplib
|
import imaplib
|
||||||
import ipaddress
|
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
@@ -10,20 +9,11 @@ import time
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from chatmaild.config import read_config, format_mail_domain, is_valid_ipv4
|
from chatmaild.config import format_mail_domain, is_valid_ipv4, read_config
|
||||||
|
|
||||||
|
|
||||||
conftestdir = Path(__file__).parent
|
conftestdir = Path(__file__).parent
|
||||||
|
|
||||||
|
|
||||||
def _is_ip(domain):
|
|
||||||
try:
|
|
||||||
ipaddress.ip_address(domain)
|
|
||||||
return True
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
config._benchresults = {}
|
config._benchresults = {}
|
||||||
config.addinivalue_line(
|
config.addinivalue_line(
|
||||||
@@ -349,7 +339,7 @@ class ChatmailACFactory:
|
|||||||
account = self.dc.add_account()
|
account = self.dc.add_account()
|
||||||
domain_deliverable = format_mail_domain(domain)
|
domain_deliverable = format_mail_domain(domain)
|
||||||
addr, password = self.gencreds(domain_deliverable)
|
addr, password = self.gencreds(domain_deliverable)
|
||||||
if _is_ip(domain):
|
if is_valid_ipv4(domain):
|
||||||
# Use DCLOGIN scheme with explicit server hosts,
|
# Use DCLOGIN scheme with explicit server hosts,
|
||||||
# matching how madmail presents its addresses to users.
|
# matching how madmail presents its addresses to users.
|
||||||
qr = (
|
qr = (
|
||||||
@@ -423,10 +413,10 @@ class Remote:
|
|||||||
def iter_output(self, logcmd="", ready=None):
|
def iter_output(self, logcmd="", ready=None):
|
||||||
getjournal = "journalctl -f" if not logcmd else logcmd
|
getjournal = "journalctl -f" if not logcmd else logcmd
|
||||||
print(self.sshdomain)
|
print(self.sshdomain)
|
||||||
match self.sshdomain:
|
if self.sshdomain in ("@local", "localhost"):
|
||||||
case "@local": command = []
|
command = []
|
||||||
case "localhost": command = []
|
else:
|
||||||
case _: command = ["ssh", f"root@{self.sshdomain}"]
|
command = ["ssh", f"root@{self.sshdomain}"]
|
||||||
[command.append(arg) for arg in getjournal.split()]
|
[command.append(arg) for arg in getjournal.split()]
|
||||||
popen = subprocess.Popen(
|
popen = subprocess.Popen(
|
||||||
command,
|
command,
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ def make_host(*fact_pairs):
|
|||||||
if cls not in facts:
|
if cls not in facts:
|
||||||
registered = ", ".join(c.__name__ for c in facts)
|
registered = ", ".join(c.__name__ for c in facts)
|
||||||
raise LookupError(
|
raise LookupError(
|
||||||
f"unexpected get_fact({cls.__name__}); "
|
f"unexpected get_fact({cls.__name__}); only registered: {registered}"
|
||||||
f"only registered: {registered}"
|
|
||||||
)
|
)
|
||||||
return facts[cls]
|
return facts[cls]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user