Pleasing the linter

This commit is contained in:
theo@manjaro 2022-07-15 15:11:45 +02:00
parent eb3c391624
commit 5f2785c6c9
6 changed files with 60 additions and 51 deletions

View file

@ -47,7 +47,6 @@ from yunohost.utils.error import YunohostValidationError, YunohostError
from yunohost.utils.network import get_public_ip
from yunohost.log import is_unit_operation
from yunohost.hook import hook_callback
from yunohost.dyndns import dyndns_update
logger = getActionLogger("yunohost.domain")
@ -638,6 +637,7 @@ def domain_dns_push(operation_logger, domains, dry_run=False, force=False, purge
if len(error_domains) > 0:
raise YunohostError("domain_dns_push_failed_domains", domains=', '.join(error_domains))
@is_unit_operation()
def domain_dns_push_unique(operation_logger, domain, dry_run=False, force=False, purge=False):
"""
@ -660,7 +660,6 @@ def domain_dns_push_unique(operation_logger, domain, dry_run=False, force=False,
# FIXME: in the future, properly unify this with yunohost dyndns update
if registrar == "yunohost":
#logger.info(m18n.n("domain_dns_registrar_yunohost"))
from yunohost.dyndns import dyndns_update
dyndns_update(domain=domain, force=force)
return {}

View file

@ -156,7 +156,7 @@ def domain_add(operation_logger, domain, subscribe=None, no_subscribe=False):
from yunohost.utils.ldap import _get_ldap_interface
from yunohost.certificate import _certificate_install_selfsigned
if subscribe!=0 and subscribe!=None:
if subscribe != 0 and subscribe is not None:
operation_logger.data_to_redact.append(subscribe)
if domain.startswith("xmpp-upload."):
@ -179,7 +179,7 @@ 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 )
dyndns = is_yunohost_dyndns_domain(domain) and len(domain.split(".")) == 3
if dyndns:
if ((subscribe==None) == (no_subscribe==False)):
if ((subscribe is None) == (no_subscribe is False)):
raise YunohostValidationError("domain_dyndns_instruction_unclear")
from yunohost.dyndns import is_subscribing_allowed
@ -260,7 +260,7 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, unsu
from yunohost.app import app_ssowatconf, app_info, app_remove
from yunohost.utils.ldap import _get_ldap_interface
if unsubscribe!=0 and unsubscribe!=None:
if unsubscribe != 0 and unsubscribe is not None:
operation_logger.data_to_redact.append(unsubscribe)
# the 'force' here is related to the exception happening in domain_add ...
@ -326,12 +326,12 @@ 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 )
dyndns = is_yunohost_dyndns_domain(domain) and len(domain.split(".")) == 3
if dyndns:
if ((unsubscribe==None) == (no_unsubscribe==False)):
if ((unsubscribe is None) == (no_unsubscribe is False)):
raise YunohostValidationError("domain_dyndns_instruction_unclear_unsubscribe")
operation_logger.start()
if not dyndns and (unsubscribe!=None or no_unsubscribe!=False):
if not dyndns and ((unsubscribe 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")
ldap = _get_ldap_interface()
@ -394,6 +394,7 @@ def domain_dyndns_subscribe(**kwargs):
dyndns_subscribe(**kwargs)
def domain_dyndns_unsubscribe(**kwargs):
"""
Unsubscribe from a DynDNS domain
@ -402,6 +403,7 @@ def domain_dyndns_unsubscribe(**kwargs):
dyndns_unsubscribe(**kwargs)
def domain_dyndns_list():
"""
Returns all currently subscribed DynDNS domains
@ -410,6 +412,7 @@ def domain_dyndns_list():
return dyndns_list()
def domain_dyndns_update(**kwargs):
"""
Update a DynDNS domain
@ -471,6 +474,7 @@ def domain_url_available(domain, path):
return len(_get_conflicting_apps(domain, path)) == 0
def _get_maindomain():
with open("/etc/yunohost/current_host", "r") as f:
maindomain = f.readline().rstrip()

View file

@ -24,7 +24,6 @@
Subscribe and Update DynDNS Hosts
"""
import os
import re
import json
import glob
import base64
@ -50,6 +49,7 @@ DYNDNS_PROVIDER = "dyndns.yunohost.org"
DYNDNS_DNS_AUTH = ["ns0.yunohost.org", "ns1.yunohost.org"]
MAX_DYNDNS_DOMAINS = 1
def is_subscribing_allowed():
"""
Check if the limit of subscribed DynDNS domains has been reached
@ -103,7 +103,9 @@ def dyndns_subscribe(operation_logger, domain=None, key=None, password=None):
# Ensure sufficiently complex password
if Moulinette.interface.type == "cli" and password == 0:
password = Moulinette.prompt(
m18n.n("ask_password"), is_password=True, confirm=True
m18n.n("ask_password"),
is_password=True,
confirm=True
)
operation_logger.data_to_redact.append(password)
assert_password_is_strong_enough("admin", password)
@ -162,7 +164,7 @@ def dyndns_subscribe(operation_logger, domain=None, key=None, password=None):
# Yeah the secret is already a base64-encoded but we double-bas64-encode it, whatever...
b64encoded_key = base64.b64encode(secret.encode()).decode()
data = {"subdomain": domain}
if password!=None:
if password is not None:
data["recovery_password"] = hashlib.sha256((domain + ":" + password.strip()).encode('utf-8')).hexdigest()
r = requests.post(
f"https://{DYNDNS_PROVIDER}/key/{b64encoded_key}?key_algo=hmac-sha512",
@ -215,7 +217,8 @@ def dyndns_unsubscribe(operation_logger, domain, password=None):
# Ensure sufficiently complex password
if Moulinette.interface.type == "cli" and not password:
password = Moulinette.prompt(
m18n.n("ask_password"), is_password=True
m18n.n("ask_password"),
is_password=True
)
operation_logger.data_to_redact.append(password)
assert_password_is_strong_enough("admin", password)
@ -251,6 +254,7 @@ def dyndns_unsubscribe(operation_logger, domain, password=None):
elif r.status_code == 404: # Invalid domain
raise YunohostError("dyndns_unsubscribe_wrong_domain")
def dyndns_list():
"""
Returns all currently subscribed DynDNS domains ( deduced from the key files )
@ -264,6 +268,7 @@ def dyndns_list():
return {"domains": files}
@is_unit_operation()
def dyndns_update(
operation_logger,

View file

@ -233,7 +233,7 @@ def tools_postinstall(
# If this is a nohost.me/noho.st, actually check for availability
if is_yunohost_dyndns_domain(domain):
if ((subscribe==None) == (no_subscribe==False)):
if ((subscribe is None) == (no_subscribe is False)):
raise YunohostValidationError("domain_dyndns_instruction_unclear")
# Check if the domain is available...

View file

@ -49,6 +49,7 @@ from yunohost.log import OperationLogger
logger = getActionLogger("yunohost.config")
CONFIG_PANEL_VERSION_SUPPORTED = 1.0
# Those js-like evaluate functions are used to eval safely visible attributes
# The goal is to evaluate in the same way than js simple-evaluate
# https://github.com/shepherdwind/simple-evaluate