cmdeploy: simplify check_necessary_dns output

This commit is contained in:
missytake
2023-12-14 18:44:28 +01:00
parent c38f1d7e54
commit 0a91aeb4a3
2 changed files with 12 additions and 25 deletions

View File

@@ -39,9 +39,7 @@ def init_cmd(args, out):
write_initial_config(args.inipath, mail_domain) write_initial_config(args.inipath, mail_domain)
out.green(f"created config file for {mail_domain} in {args.inipath}") out.green(f"created config file for {mail_domain} in {args.inipath}")
check_necessary_dns( check_necessary_dns(
args,
out, out,
"\nNow you should add %dnsentry% at your DNS provider:\n",
mail_domain, mail_domain,
) )
@@ -59,9 +57,7 @@ def run_cmd(args, out):
"""Deploy chatmail services on the remote server.""" """Deploy chatmail services on the remote server."""
mail_domain = args.config.mail_domain mail_domain = args.config.mail_domain
if not check_necessary_dns( if not check_necessary_dns(
args,
out, out,
"\nmissing DNS entries, please add %dnsentry% at your DNS provider:\n",
mail_domain, mail_domain,
): ):
sys.exit(1) sys.exit(1)

View File

@@ -175,14 +175,8 @@ def show_dns(args, out):
) )
def check_necessary_dns(args, out, msg, mail_domain): def check_necessary_dns(out, mail_domain):
"""Check whether $mail_domain and mta-sts.$mail_domain resolve. """Check whether $mail_domain and mta-sts.$mail_domain resolve."""
:param args: the argparse args object
:param out: an object to control CLI output
:param msg: a string like: "Now you should add %dnsentry% at your DNS provider:\n"
:param mail_domain: the mail_domain of the chatmail server
"""
dns = DNS(out, mail_domain) dns = DNS(out, mail_domain)
try: try:
ipaddress = dns.resolve(mail_domain) ipaddress = dns.resolve(mail_domain)
@@ -190,21 +184,18 @@ def check_necessary_dns(args, out, msg, mail_domain):
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
ipaddress = None ipaddress = None
mta_ipadress = None mta_ipadress = None
entries = 0 to_print = []
to_print = [msg]
if not ipaddress: if not ipaddress:
entries += 1
to_print.append(f"\tA\t{mail_domain}.\t\t<your server's IPv4 address>") to_print.append(f"\tA\t{mail_domain}.\t\t<your server's IPv4 address>")
if not mta_ipadress or mta_ipadress != ipaddress: elif not mta_ipadress or mta_ipadress != ipaddress:
entries += 1
to_print.append(f"\tCNAME\tmta-sts.{mail_domain}.\t{mail_domain}.") to_print.append(f"\tCNAME\tmta-sts.{mail_domain}.\t{mail_domain}.")
if entries == 1: if to_print:
singular = "this entry" to_print.insert(
elif entries == 2: 0,
singular = "these entries" "\nFor chatmail to work, you need to configure this at your DNS provider:\n",
)
for line in to_print:
print(line)
print()
else: else:
return True return True
to_print[0] = to_print[0].replace("%dnsentry%", singular)
for line in to_print:
print(line)
print()