[enh] Semantic

This commit is contained in:
ljf 2023-01-08 00:35:34 +01:00
parent 129f5cce95
commit a21567b27d
No known key found for this signature in database
5 changed files with 39 additions and 29 deletions

View file

@ -73,6 +73,7 @@
"ask_new_domain": "New domain", "ask_new_domain": "New domain",
"ask_new_path": "New path", "ask_new_path": "New path",
"ask_password": "Password", "ask_password": "Password",
"ask_dyndns_recovery_password": "DynDNS recovey password",
"ask_user_domain": "Domain to use for the user's email address and XMPP account", "ask_user_domain": "Domain to use for the user's email address and XMPP account",
"backup_abstract_method": "This backup method has yet to be implemented", "backup_abstract_method": "This backup method has yet to be implemented",
"backup_actually_backuping": "Creating a backup archive from the collected files...", "backup_actually_backuping": "Creating a backup archive from the collected files...",

View file

@ -463,8 +463,7 @@ domain:
full: --no-subscribe full: --no-subscribe
help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service
action: store_true action: store_true
-s: --dyndns-password-recovery:
full: --subscribe
metavar: PASSWORD metavar: PASSWORD
nargs: "?" nargs: "?"
const: 0 const: 0
@ -494,8 +493,7 @@ domain:
full: --no-unsubscribe full: --no-unsubscribe
help: If removing a DynDNS domain, only remove the domain, without unsubscribing from the DynDNS service help: If removing a DynDNS domain, only remove the domain, without unsubscribing from the DynDNS service
action: store_true action: store_true
-u: --dyndns-password-recovery:
full: --unsubscribe
metavar: PASSWORD metavar: PASSWORD
nargs: "?" nargs: "?"
const: 0 const: 0
@ -1582,8 +1580,7 @@ tools:
full: --no-subscribe full: --no-subscribe
help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service
action: store_true action: store_true
-s: --dyndns-password-recovery:
full: --subscribe
metavar: PASSWORD metavar: PASSWORD
nargs: "?" nargs: "?"
const: 0 const: 0

View file

@ -140,24 +140,25 @@ def _get_parent_domain_of(domain):
return _get_parent_domain_of(parent_domain) return _get_parent_domain_of(parent_domain)
@is_unit_operation(exclude=["subscribe"]) @is_unit_operation(exclude=["dyndns_password_recovery"])
def domain_add(operation_logger, domain, subscribe=None, no_subscribe=False): def domain_add(operation_logger, domain, dyndns_password_recovery=None, no_subscribe=False):
""" """
Create a custom domain Create a custom domain
Keyword argument: Keyword argument:
domain -- Domain name to add domain -- Domain name to add
dyndns -- Subscribe to DynDNS dyndns -- Subscribe to DynDNS
subscribe -- Password used to later unsubscribe from DynDNS dyndns_password_recovery -- Password used to later unsubscribe from DynDNS
no_unsubscribe -- If we want to just add the DynDNS domain to the list, without subscribing no_unsubscribe -- If we want to just add the DynDNS domain to the list, without subscribing
""" """
from yunohost.hook import hook_callback from yunohost.hook import hook_callback
from yunohost.app import app_ssowatconf from yunohost.app import app_ssowatconf
from yunohost.utils.ldap import _get_ldap_interface from yunohost.utils.ldap import _get_ldap_interface
from yunohost.utils.password import assert_password_is_strong_enough
from yunohost.certificate import _certificate_install_selfsigned from yunohost.certificate import _certificate_install_selfsigned
if subscribe != 0 and subscribe is not None: if dyndns_password_recovery != 0 and dyndns_password_recovery is not None:
operation_logger.data_to_redact.append(subscribe) operation_logger.data_to_redact.append(dyndns_password_recovery)
if domain.startswith("xmpp-upload."): if domain.startswith("xmpp-upload."):
raise YunohostValidationError("domain_cannot_add_xmpp_upload") raise YunohostValidationError("domain_cannot_add_xmpp_upload")
@ -179,7 +180,18 @@ def domain_add(operation_logger, domain, subscribe=None, no_subscribe=False):
# Detect if this is a DynDNS domain ( and not a subdomain of a DynDNS domain ) # Detect if this is a DynDNS domain ( and not a subdomain of a DynDNS domain )
dyndns = is_yunohost_dyndns_domain(domain) and len(domain.split(".")) == 3 dyndns = is_yunohost_dyndns_domain(domain) and len(domain.split(".")) == 3
if dyndns: if dyndns:
if ((subscribe is None) == (no_subscribe is False)): if not no_subscribe and not dyndns_password_recovery:
if Moulinette.interface.type == "api":
raise YunohostValidationError("domain_dyndns_missing_password")
else:
dyndns_password_recovery = Moulinette.prompt(
m18n.n("ask_dyndns_recovery_password"), is_password=True, confirm=True
)
# Ensure sufficiently complex password
assert_password_is_strong_enough("admin", dyndns_password_recovery)
if ((dyndns_password_recovery is None) == (no_subscribe is False)):
raise YunohostValidationError("domain_dyndns_instruction_unclear") raise YunohostValidationError("domain_dyndns_instruction_unclear")
from yunohost.dyndns import is_subscribing_allowed from yunohost.dyndns import is_subscribing_allowed
@ -189,12 +201,12 @@ def domain_add(operation_logger, domain, subscribe=None, no_subscribe=False):
raise YunohostValidationError("domain_dyndns_already_subscribed") raise YunohostValidationError("domain_dyndns_already_subscribed")
operation_logger.start() operation_logger.start()
if not dyndns and (subscribe is not None or no_subscribe): if not dyndns and (dyndns_password_recovery is not None or no_subscribe):
logger.warning("This domain is not a DynDNS one, no need for the --subscribe or --no-subscribe option") logger.warning("This domain is not a DynDNS one, no need for the --dyndns-password-recovery or --no-subscribe option")
if dyndns and not no_subscribe: if dyndns and not no_subscribe:
# Actually subscribe # Actually subscribe
domain_dyndns_subscribe(domain=domain, password=subscribe) domain_dyndns_subscribe(domain=domain, password=dyndns_password_recovery)
_certificate_install_selfsigned([domain], True) _certificate_install_selfsigned([domain], True)
@ -243,8 +255,8 @@ def domain_add(operation_logger, domain, subscribe=None, no_subscribe=False):
logger.success(m18n.n("domain_created")) logger.success(m18n.n("domain_created"))
@is_unit_operation(exclude=["unsubscribe"]) @is_unit_operation(exclude=["dyndns_password_recovery"])
def domain_remove(operation_logger, domain, remove_apps=False, force=False, unsubscribe=None, no_unsubscribe=False): def domain_remove(operation_logger, domain, remove_apps=False, force=False, dyndns_password_recovery=None, no_unsubscribe=False):
""" """
Delete domains Delete domains
@ -253,15 +265,15 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, unsu
remove_apps -- Remove applications installed on the domain remove_apps -- Remove applications installed on the domain
force -- Force the domain removal and don't not ask confirmation to force -- Force the domain removal and don't not ask confirmation to
remove apps if remove_apps is specified remove apps if remove_apps is specified
unsubscribe -- Recovery password used at the creation of the DynDNS domain dyndns_password_recovery -- Recovery password used at the creation of the DynDNS domain
no_unsubscribe -- If we just remove the DynDNS domain, without unsubscribing no_unsubscribe -- If we just remove the DynDNS domain, without unsubscribing
""" """
from yunohost.hook import hook_callback from yunohost.hook import hook_callback
from yunohost.app import app_ssowatconf, app_info, app_remove from yunohost.app import app_ssowatconf, app_info, app_remove
from yunohost.utils.ldap import _get_ldap_interface from yunohost.utils.ldap import _get_ldap_interface
if unsubscribe != 0 and unsubscribe is not None: if dyndns_password_recovery != 0 and dyndns_password_recovery is not None:
operation_logger.data_to_redact.append(unsubscribe) operation_logger.data_to_redact.append(dyndns_password_recovery)
# the 'force' here is related to the exception happening in domain_add ... # the 'force' here is related to the exception happening in domain_add ...
# we don't want to check the domain exists because the ldap add may have # we don't want to check the domain exists because the ldap add may have
@ -326,13 +338,13 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, unsu
# Detect if this is a DynDNS domain ( and not a subdomain of a DynDNS domain ) # Detect if this is a DynDNS domain ( and not a subdomain of a DynDNS domain )
dyndns = is_yunohost_dyndns_domain(domain) and len(domain.split(".")) == 3 dyndns = is_yunohost_dyndns_domain(domain) and len(domain.split(".")) == 3
if dyndns: if dyndns:
if ((unsubscribe is None) == (no_unsubscribe is False)): if ((dyndns_password_recovery is None) == (no_unsubscribe is False)):
raise YunohostValidationError("domain_dyndns_instruction_unclear_unsubscribe") raise YunohostValidationError("domain_dyndns_instruction_unclear_unsubscribe")
operation_logger.start() operation_logger.start()
if not dyndns and ((unsubscribe is not None) or (no_unsubscribe is not False)): if not dyndns and ((dyndns_password_recovery is not None) or (no_unsubscribe is not False)):
logger.warning("This domain is not a DynDNS one, no need for the --unsubscribe or --no-unsubscribe option") logger.warning("This domain is not a DynDNS one, no need for the --dyndns_password_recovery or --no-unsubscribe option")
ldap = _get_ldap_interface() ldap = _get_ldap_interface()
try: try:
@ -381,7 +393,7 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, unsu
# If a password is provided, delete the DynDNS record # If a password is provided, delete the DynDNS record
if dyndns and not no_unsubscribe: if dyndns and not no_unsubscribe:
# Actually unsubscribe # Actually unsubscribe
domain_dyndns_unsubscribe(domain=domain, password=unsubscribe) domain_dyndns_unsubscribe(domain=domain, password=dyndns_password_recovery)
logger.success(m18n.n("domain_deleted")) logger.success(m18n.n("domain_deleted"))

View file

@ -76,7 +76,7 @@ def test_domain_add_subscribe():
time.sleep(35) # Dynette blocks requests that happen too frequently time.sleep(35) # Dynette blocks requests that happen too frequently
assert TEST_DYNDNS_DOMAIN not in domain_list()["domains"] assert TEST_DYNDNS_DOMAIN not in domain_list()["domains"]
domain_add(TEST_DYNDNS_DOMAIN, subscribe=TEST_DYNDNS_PASSWORD) domain_add(TEST_DYNDNS_DOMAIN, dyndns_password_recovery=TEST_DYNDNS_PASSWORD)
assert TEST_DYNDNS_DOMAIN in domain_list()["domains"] assert TEST_DYNDNS_DOMAIN in domain_list()["domains"]

View file

@ -180,12 +180,12 @@ def _detect_virt():
return out.split()[0] return out.split()[0]
@is_unit_operation(exclude=["subscribe", "password"]) @is_unit_operation(exclude=["dyndns_password_recovery", "password"])
def tools_postinstall( def tools_postinstall(
operation_logger, operation_logger,
domain, domain,
password, password,
subscribe=None, dyndns_password_recovery=None,
no_subscribe=False, no_subscribe=False,
force_password=False, force_password=False,
force_diskspace=False, force_diskspace=False,
@ -232,7 +232,7 @@ def tools_postinstall(
# If this is a nohost.me/noho.st, actually check for availability # If this is a nohost.me/noho.st, actually check for availability
if is_yunohost_dyndns_domain(domain): if is_yunohost_dyndns_domain(domain):
if ((subscribe is None) == (no_subscribe is False)): if ((dyndns_password_recovery is None) == (no_subscribe is False)):
raise YunohostValidationError("domain_dyndns_instruction_unclear") raise YunohostValidationError("domain_dyndns_instruction_unclear")
# Check if the domain is available... # Check if the domain is available...
@ -257,7 +257,7 @@ def tools_postinstall(
logger.info(m18n.n("yunohost_installing")) logger.info(m18n.n("yunohost_installing"))
# New domain config # New domain config
domain_add(domain, subscribe=subscribe, no_subscribe=no_subscribe) domain_add(domain, dyndns_password_recovery=dyndns_password_recovery, no_subscribe=no_subscribe)
domain_main_domain(domain) domain_main_domain(domain)
# Update LDAP admin and create home dir # Update LDAP admin and create home dir