From 4b9dbd92ebe2fce1d02873483491abc9a86f3584 Mon Sep 17 00:00:00 2001 From: MercierCorentin Date: Fri, 4 Jun 2021 09:42:04 +0200 Subject: [PATCH] Moved get_dns_zone_from_domain from utils/network to utils/dns --- src/yunohost/utils/dns.py | 23 ++++++++++++++++++++++- src/yunohost/utils/network.py | 21 --------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/yunohost/utils/dns.py b/src/yunohost/utils/dns.py index 3033743d1..26347101f 100644 --- a/src/yunohost/utils/dns.py +++ b/src/yunohost/utils/dns.py @@ -35,4 +35,25 @@ def get_public_suffix(domain): domain_prefix = domain_name[0:-(1 + len(public_suffix))] public_suffix = domain_prefix.plit(".")[-1] + "." + public_suffix - return public_suffix \ No newline at end of file + return public_suffix + +def get_dns_zone_from_domain(domain): + """ + Get the DNS zone of a domain + + Keyword arguments: + domain -- The domain name + + """ + separator = "." + domain_subs = domain.split(separator) + for i in range(0, len(domain_subs)): + answer = dig(separator.join(domain_subs), rdtype="NS", full_answers=True) + if answer[0] == "ok" : + return separator.join(domain_subs) + elif answer[1][0] == "NXDOMAIN" : + return None + domain_subs.pop(0) + + # Should not be executed + return None \ No newline at end of file diff --git a/src/yunohost/utils/network.py b/src/yunohost/utils/network.py index 895a2fe5a..9423199bb 100644 --- a/src/yunohost/utils/network.py +++ b/src/yunohost/utils/network.py @@ -184,27 +184,6 @@ def dig( answers = [answer.to_text() for answer in answers] return ("ok", answers) - -def get_dns_zone_from_domain(domain): - """ - Get the DNS zone of a domain - - Keyword arguments: - domain -- The domain name - - """ - separator = "." - domain_subs = domain.split(separator) - for i in range(0, len(domain_subs)): - answer = dig(separator.join(domain_subs), rdtype="NS", full_answers=True) - if answer[0] == "ok" : - return separator.join(domain_subs) - elif answer[1][0] == "NXDOMAIN" : - return None - domain_subs.pop(0) - - # Should not be executed - return None def _extract_inet(string, skip_netmask=False, skip_loopback=True): """