mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
dyndns: handle too many requests in availability testing
This commit is contained in:
parent
5110cd0800
commit
cbb85f8c3b
2 changed files with 14 additions and 4 deletions
|
@ -396,6 +396,7 @@
|
|||
"downloading": "Downloading...",
|
||||
"dpkg_is_broken": "You cannot do this right now because dpkg/APT (the system package managers) seems to be in a broken state... You can try to solve this issue by connecting through SSH and running `sudo apt install --fix-broken` and/or `sudo dpkg --configure -a` and/or `sudo dpkg --audit`.",
|
||||
"dpkg_lock_not_available": "This command can't be run right now because another program seems to be using the lock of dpkg (the system package manager)",
|
||||
"dyndns_availability_too_many_requests": "YunoHost's free domain service received too many requests from you, wait 1 minute or so before trying again.",
|
||||
"dyndns_could_not_check_available": "Could not check if {domain} is available on {provider}.",
|
||||
"dyndns_domain_not_provided": "DynDNS provider {provider} cannot provide domain {domain}.",
|
||||
"dyndns_ip_update_failed": "Could not update IP address to DynDNS",
|
||||
|
|
|
@ -63,19 +63,28 @@ def _dyndns_available(domain):
|
|||
Returns:
|
||||
True if the domain is available, False otherwise.
|
||||
"""
|
||||
import requests # lazy loading this module for performance reasons
|
||||
|
||||
logger.debug(f"Checking if domain {domain} is available on {DYNDNS_PROVIDER} ...")
|
||||
|
||||
try:
|
||||
r = download_json(
|
||||
f"https://{DYNDNS_PROVIDER}/test/{domain}", expected_status_code=None
|
||||
)
|
||||
r = requests.get(f"https://{DYNDNS_PROVIDER}/test/{domain}", timeout=30)
|
||||
except MoulinetteError as e:
|
||||
logger.error(str(e))
|
||||
raise YunohostError(
|
||||
"dyndns_could_not_check_available", domain=domain, provider=DYNDNS_PROVIDER
|
||||
)
|
||||
|
||||
return r == f"Domain {domain} is available"
|
||||
if r.status_code == 200:
|
||||
return r == f"Domain {domain} is available"
|
||||
elif r.status_code == 409:
|
||||
return False
|
||||
elif r.status_code == 429:
|
||||
raise YunohostValidationError("dyndns_availability_too_many_requests")
|
||||
else:
|
||||
raise YunohostError(
|
||||
"dyndns_could_not_check_available", domain=domain, provider=DYNDNS_PROVIDER
|
||||
)
|
||||
|
||||
|
||||
@is_unit_operation(exclude=["recovery_password"])
|
||||
|
|
Loading…
Add table
Reference in a new issue