From 0a91aeb4a3bb5dfe94015458ef345bb97c414c2b Mon Sep 17 00:00:00 2001 From: missytake Date: Thu, 14 Dec 2023 18:44:28 +0100 Subject: [PATCH] cmdeploy: simplify check_necessary_dns output --- cmdeploy/src/cmdeploy/cmdeploy.py | 4 ---- cmdeploy/src/cmdeploy/dns.py | 33 +++++++++++-------------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index 4933a629..c0fe0721 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -39,9 +39,7 @@ def init_cmd(args, out): write_initial_config(args.inipath, mail_domain) out.green(f"created config file for {mail_domain} in {args.inipath}") check_necessary_dns( - args, out, - "\nNow you should add %dnsentry% at your DNS provider:\n", mail_domain, ) @@ -59,9 +57,7 @@ def run_cmd(args, out): """Deploy chatmail services on the remote server.""" mail_domain = args.config.mail_domain if not check_necessary_dns( - args, out, - "\nmissing DNS entries, please add %dnsentry% at your DNS provider:\n", mail_domain, ): sys.exit(1) diff --git a/cmdeploy/src/cmdeploy/dns.py b/cmdeploy/src/cmdeploy/dns.py index 9af6d046..bb4e49df 100644 --- a/cmdeploy/src/cmdeploy/dns.py +++ b/cmdeploy/src/cmdeploy/dns.py @@ -175,14 +175,8 @@ def show_dns(args, out): ) -def check_necessary_dns(args, out, msg, mail_domain): - """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 - """ +def check_necessary_dns(out, mail_domain): + """Check whether $mail_domain and mta-sts.$mail_domain resolve.""" dns = DNS(out, mail_domain) try: ipaddress = dns.resolve(mail_domain) @@ -190,21 +184,18 @@ def check_necessary_dns(args, out, msg, mail_domain): except subprocess.CalledProcessError: ipaddress = None mta_ipadress = None - entries = 0 - to_print = [msg] + to_print = [] if not ipaddress: - entries += 1 to_print.append(f"\tA\t{mail_domain}.\t\t") - if not mta_ipadress or mta_ipadress != ipaddress: - entries += 1 + elif not mta_ipadress or mta_ipadress != ipaddress: to_print.append(f"\tCNAME\tmta-sts.{mail_domain}.\t{mail_domain}.") - if entries == 1: - singular = "this entry" - elif entries == 2: - singular = "these entries" + if to_print: + to_print.insert( + 0, + "\nFor chatmail to work, you need to configure this at your DNS provider:\n", + ) + for line in to_print: + print(line) + print() else: return True - to_print[0] = to_print[0].replace("%dnsentry%", singular) - for line in to_print: - print(line) - print()