From 840bed5222f23dd3cc07713226282d3505047ad2 Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Tue, 5 Jul 2022 15:10:04 +0200 Subject: [PATCH] `yunohost domain remove` auto-detects DynDNS domains and now uses --unsubscribe and --no-unsubscribe --- share/actionsmap.yml | 11 ++++++++--- src/domain.py | 22 ++++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/share/actionsmap.yml b/share/actionsmap.yml index bb9fa2ae7..eb24de49f 100644 --- a/share/actionsmap.yml +++ b/share/actionsmap.yml @@ -484,11 +484,16 @@ domain: full: --force help: Do not ask confirmation to remove apps action: store_true - -p: - full: --password + -n: + full: --no-unsubscribe + help: If removing a DynDNS domain, only remove the domain, without unsubscribing from the DynDNS service + action: store_true + -u: + full: --unsubscribe + metavar: PASSWORD nargs: "?" const: 0 - help: Password used to delete the domain from DynDNS + help: If removing a DynDNS domain, unsubscribe from the DynDNS service with a password extra: pattern: *pattern_password diff --git a/src/domain.py b/src/domain.py index e6a61cea0..9bd6a05bd 100644 --- a/src/domain.py +++ b/src/domain.py @@ -139,7 +139,8 @@ def domain_add(operation_logger, domain, subscribe=None, no_subscribe=False): Keyword argument: domain -- Domain name to add dyndns -- Subscribe to DynDNS - password -- Password used to later unsubscribe from DynDNS + subscribe -- Password used to later unsubscribe from DynDNS + no_unsubscribe -- If we want to just add the DynDNS domain to the list, without subscribing """ from yunohost.hook import hook_callback from yunohost.app import app_ssowatconf @@ -166,7 +167,6 @@ def domain_add(operation_logger, domain, subscribe=None, no_subscribe=False): # DynDNS domain dyndns = is_yunohost_dyndns_domain(domain) if dyndns: - print(subscribe,no_subscribe) if ((subscribe==None) == (no_subscribe==False)): raise YunohostValidationError("domain_dyndns_instruction_unclear") @@ -238,7 +238,7 @@ def domain_add(operation_logger, domain, subscribe=None, no_subscribe=False): @is_unit_operation() -def domain_remove(operation_logger, domain, remove_apps=False, force=False, password=None): +def domain_remove(operation_logger, domain, remove_apps=False, force=False, unsubscribe=None,no_unsubscribe=False): """ Delete domains @@ -247,7 +247,8 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, pass remove_apps -- Remove applications installed on the domain force -- Force the domain removal and don't not ask confirmation to remove apps if remove_apps is specified - password -- Recovery password used at the creation of the DynDNS domain + unsubscribe -- Recovery password used at the creation of the DynDNS domain + no_unsubscribe -- If we just remove the DynDNS domain, without unsubscribing """ from yunohost.hook import hook_callback from yunohost.app import app_ssowatconf, app_info, app_remove @@ -312,9 +313,18 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, pass "domain_uninstall_app_first", apps="\n".join([x[1] for x in apps_on_that_domain]), ) + + # DynDNS domain + dyndns = is_yunohost_dyndns_domain(domain) + if dyndns: + if ((unsubscribe==None) == (no_unsubscribe==False)): + raise YunohostValidationError("domain_dyndns_instruction_unclear") operation_logger.start() + if not dyndns and (unsubscribe!=None or no_unsubscribe!=False): + logger.warning("This domain is not a DynDNS one, no need for the --unsubscribe or --no-unsubscribe option") + ldap = _get_ldap_interface() try: ldap.remove("virtualdomain=" + domain + ",ou=domains") @@ -360,9 +370,9 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, pass hook_callback("post_domain_remove", args=[domain]) # If a password is provided, delete the DynDNS record - if password!=None: + if dyndns and not no_unsubscribe: # Actually unsubscribe - domain_dyndns_unsubscribe(domain=domain,password=password) + domain_dyndns_unsubscribe(domain=domain,password=unsubscribe) logger.success(m18n.n("domain_deleted"))