From ab86d13b1ec1eb96f8b60332b65a439771c90b98 Mon Sep 17 00:00:00 2001 From: Paco Date: Fri, 18 Jun 2021 19:14:51 +0200 Subject: [PATCH] Update _load_domain_settings to load only requested domains --- locales/en.json | 2 +- src/yunohost/domain.py | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/locales/en.json b/locales/en.json index 75912cab5..712ecb844 100644 --- a/locales/en.json +++ b/locales/en.json @@ -285,7 +285,7 @@ "domain_dyndns_already_subscribed": "You have already subscribed to a DynDNS domain", "domain_dyndns_root_unknown": "Unknown DynDNS root domain", "domain_exists": "The domain already exists", - "domain_property_unknown": "The property {property} dooesn't exist", + "domain_property_unknown": "The property {property} doesn't exist", "domain_hostname_failed": "Unable to set new hostname. This might cause an issue later (it might be fine).", "domain_registrar_unknown": "This registrar is unknown. Look for yours with the command `yunohost domain catalog`", "domain_remove_confirm_apps_removal": "Removing this domain will remove those applications:\n{apps}\n\nAre you sure you want to do that? [{answers}]", diff --git a/src/yunohost/domain.py b/src/yunohost/domain.py index 6c90b533e..c13234d0b 100644 --- a/src/yunohost/domain.py +++ b/src/yunohost/domain.py @@ -729,14 +729,24 @@ def _get_DKIM(domain): ) -# FIXME split the loading of the domain settings → domain by domain (& file by file) -def _load_domain_settings(): +def _load_domain_settings(for_domains=[]): """ - Retrieve entries in domains/[domain].yml + Retrieve entries in /etc/yunohost/domains/[domain].yml And fill the holes if any """ # Retrieve actual domain list get_domain_list = domain_list() + domains = [] + + if for_domains: + # keep only the requested domains + domains = filter(lambda domain : domain in for_domains, get_domain_list["domains"]) + # check that all requested domains are there + unknown_domains = filter(lambda domain : not domain in domains, for_domains) + unknown_domain = next(unknown_domains, None) + if unknown_domain != None: + raise YunohostValidationError("domain_name_unknown", domain=unknown_domain) + # Create sanitized data new_domains = dict() @@ -744,7 +754,7 @@ def _load_domain_settings(): # Load main domain maindomain = get_domain_list["main"] - for domain in get_domain_list["domains"]: + for domain in domains: # Retrieve entries in the YAML filepath = f"{DOMAIN_SETTINGS_DIR}/{domain}.yml" on_disk_settings = {} @@ -799,7 +809,8 @@ def domain_setting(domain, key, value=None, delete=False): """ - domains = _load_domain_settings() + domains = _load_domain_settings([ domain ]) + if not domain in domains.keys(): # TODO add locales raise YunohostError("domain_name_unknown", domain=domain) @@ -871,8 +882,7 @@ def _set_domain_settings(domain, domain_settings): settings -- Dict with doamin settings """ - domains = _load_domain_settings() - if not domain in domains.keys(): + if domain not in domain_list()["domains"]: raise YunohostError("domain_name_unknown", domain=domain) # First create the DOMAIN_SETTINGS_DIR if it doesn't exist @@ -885,9 +895,7 @@ def _set_domain_settings(domain, domain_settings): def _load_zone_of_domain(domain): - domains = _load_domain_settings() - if not domain in domains.keys(): - # TODO add locales + if domain not in domain_list()["domains"]: raise YunohostError("domain_name_unknown", domain=domain) return domains[domain]["dns_zone"]