Merge pull request #1514 from YunoHost/get-parent

call _get_parent_domain_of to ensure getting any level parent
This commit is contained in:
Alexandre Aubin 2022-10-07 17:03:18 +02:00 committed by GitHub
commit 43b7a1a9a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 14 deletions

View file

@ -50,9 +50,7 @@ name = "Features"
name = "DNS" name = "DNS"
[dns.registrar] [dns.registrar]
optional = true # This part is automatically generated in DomainConfigPanel
# This part is automatically generated in DomainConfigPanel
# [dns.advanced] # [dns.advanced]
# #

View file

@ -41,6 +41,7 @@ from yunohost.domain import (
_get_domain_settings, _get_domain_settings,
_set_domain_settings, _set_domain_settings,
_list_subdomains_of, _list_subdomains_of,
_get_parent_domain_of,
) )
from yunohost.utils.dns import dig, is_yunohost_dyndns_domain, is_special_use_tld from yunohost.utils.dns import dig, is_yunohost_dyndns_domain, is_special_use_tld
from yunohost.utils.error import YunohostValidationError, YunohostError from yunohost.utils.error import YunohostValidationError, YunohostError
@ -446,8 +447,8 @@ def _get_dns_zone_for_domain(domain):
# This is another strick to try to prevent this function from being # This is another strick to try to prevent this function from being
# a bottleneck on system with 1 main domain + 10ish subdomains # a bottleneck on system with 1 main domain + 10ish subdomains
# when building the dns conf for the main domain (which will call domain_config_get, etc...) # when building the dns conf for the main domain (which will call domain_config_get, etc...)
parent_domain = domain.split(".", 1)[1] parent_domain = _get_parent_domain_of(domain)
if parent_domain in domain_list()["domains"]: if parent_domain:
parent_cache_file = f"{cache_folder}/{parent_domain}" parent_cache_file = f"{cache_folder}/{parent_domain}"
if ( if (
os.path.exists(parent_cache_file) os.path.exists(parent_cache_file)
@ -512,17 +513,19 @@ def _get_registrar_config_section(domain):
from lexicon.providers.auto import _relevant_provider_for_domain from lexicon.providers.auto import _relevant_provider_for_domain
registrar_infos = {} registrar_infos = {
"name": m18n.n('registrar_infos'), # This is meant to name the config panel section, for proper display in the webadmin
}
dns_zone = _get_dns_zone_for_domain(domain) dns_zone = _get_dns_zone_for_domain(domain)
# If parent domain exists in yunohost # If parent domain exists in yunohost
parent_domain = domain.split(".", 1)[1] parent_domain = _get_parent_domain_of(domain, topest=True)
if parent_domain in domain_list()["domains"]: if parent_domain:
# Dirty hack to have a link on the webadmin # Dirty hack to have a link on the webadmin
if Moulinette.interface.type == "api": if Moulinette.interface.type == "api":
parent_domain_link = f"[{parent_domain}](#/domains/{parent_domain}/config)" parent_domain_link = f"[{parent_domain}](#/domains/{parent_domain}/dns)"
else: else:
parent_domain_link = parent_domain parent_domain_link = parent_domain
@ -532,7 +535,7 @@ def _get_registrar_config_section(domain):
"style": "info", "style": "info",
"ask": m18n.n( "ask": m18n.n(
"domain_dns_registrar_managed_in_parent_domain", "domain_dns_registrar_managed_in_parent_domain",
parent_domain=domain, parent_domain=parent_domain,
parent_domain_link=parent_domain_link, parent_domain_link=parent_domain_link,
), ),
"value": "parent_domain", "value": "parent_domain",
@ -647,7 +650,7 @@ def domain_dns_push(operation_logger, domain, dry_run=False, force=False, purge=
return {} return {}
if registrar == "parent_domain": if registrar == "parent_domain":
parent_domain = domain.split(".", 1)[1] parent_domain = _get_parent_domain_of(domain, topest=True)
registar, registrar_credentials = _get_registar_settings(parent_domain) registar, registrar_credentials = _get_registar_settings(parent_domain)
if any(registrar_credentials.values()): if any(registrar_credentials.values()):
raise YunohostValidationError( raise YunohostValidationError(

View file

@ -95,7 +95,7 @@ def _get_domains(exclude_subdomains=False):
return [ return [
domain domain
for domain in domain_list_cache for domain in domain_list_cache
if not _get_parent_domain_of(domain, return_self=False) if not _get_parent_domain_of(domain)
] ]
return domain_list_cache return domain_list_cache
@ -167,7 +167,7 @@ def domain_info(domain):
"registrar": registrar, "registrar": registrar,
"apps": apps, "apps": apps,
"main": _get_maindomain() == domain, "main": _get_maindomain() == domain,
"topest_parent": _get_parent_domain_of(domain, return_self=True, topest=True), "topest_parent": _get_parent_domain_of(domain, topest=True),
# TODO : add parent / child domains ? # TODO : add parent / child domains ?
} }
@ -189,7 +189,7 @@ def _list_subdomains_of(parent_domain):
return out return out
def _get_parent_domain_of(domain, return_self=True, topest=False): def _get_parent_domain_of(domain, return_self=False, topest=False):
_assert_domain_exists(domain) _assert_domain_exists(domain)