mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge branch 'enh-dns-autoconf' of https://github.com/MercierCorentin/yunohost into enh-dns-autoconf
This commit is contained in:
commit
132085bceb
2 changed files with 56 additions and 114 deletions
|
@ -551,57 +551,22 @@ domain:
|
||||||
pattern: *pattern_domain
|
pattern: *pattern_domain
|
||||||
path:
|
path:
|
||||||
help: The path to check (e.g. /coffee)
|
help: The path to check (e.g. /coffee)
|
||||||
|
### domain_setting()
|
||||||
subcategories:
|
setting:
|
||||||
config:
|
action_help: Set or get an app setting value
|
||||||
subcategory_help: Domains DNS settings
|
api: GET /domains/<domain>/settings
|
||||||
actions:
|
arguments:
|
||||||
# domain_config_list
|
domain:
|
||||||
list:
|
help: Domaine name
|
||||||
action_help: Get settings for all domains
|
key:
|
||||||
api: GET /domains/list
|
help: Key to get/set
|
||||||
|
-v:
|
||||||
# domain_config_show
|
full: --value
|
||||||
show:
|
help: Value to set
|
||||||
action_help: Get settings for all domains
|
-d:
|
||||||
api: GET /domains/<domain>/show
|
full: --delete
|
||||||
arguments:
|
help: Delete the key
|
||||||
domain:
|
action: store_true
|
||||||
help: Target domain
|
|
||||||
extra:
|
|
||||||
pattern: *pattern_domain
|
|
||||||
|
|
||||||
# domain_config_get
|
|
||||||
get:
|
|
||||||
action_help: Get specific setting of a domain
|
|
||||||
api: GET /domains/<domain>/<key>
|
|
||||||
arguments:
|
|
||||||
domain:
|
|
||||||
help: Target domain
|
|
||||||
extra:
|
|
||||||
pattern: *pattern_domain
|
|
||||||
key:
|
|
||||||
help: Setting requested. One of ttl, xmpp, mail, owned_dns_zone
|
|
||||||
extra:
|
|
||||||
pattern: &pattern_domain_key
|
|
||||||
- !!str ^(ttl)|(xmpp)|(mail)|(owned_dns_zone)|$
|
|
||||||
- "pattern_domain_key"
|
|
||||||
|
|
||||||
# domain_config_set
|
|
||||||
set:
|
|
||||||
action_help: Set a setting of a domain
|
|
||||||
api: POST /domains/<domain>/<key>
|
|
||||||
arguments:
|
|
||||||
domain:
|
|
||||||
help: Target domain
|
|
||||||
extra:
|
|
||||||
pattern: *pattern_domain
|
|
||||||
key:
|
|
||||||
help: Setting requested. One of ttl (Time To Live of this domain's DNS records), xmpp (Configure XMPP in this domain's DNS records?), mail (Configure mail in this domain's DNS records?), owned_dns_zone (Is it a full domain, i.e not a subdomain?)
|
|
||||||
extra:
|
|
||||||
pattern: *pattern_domain_key
|
|
||||||
value:
|
|
||||||
help: Value of the setting. Must be a positive integer number for "ttl", or one of ("True", "False", "true", "false", "1", "0") for other settings
|
|
||||||
|
|
||||||
|
|
||||||
### domain_info()
|
### domain_info()
|
||||||
|
|
|
@ -728,38 +728,48 @@ def _load_domain_settings():
|
||||||
|
|
||||||
return new_domains
|
return new_domains
|
||||||
|
|
||||||
|
def domain_setting(domain, key, value=None, delete=False):
|
||||||
def domain_config_list():
|
|
||||||
"""
|
"""
|
||||||
Show settings of all domains
|
Set or get an app setting value
|
||||||
|
|
||||||
|
Keyword argument:
|
||||||
|
value -- Value to set
|
||||||
|
app -- App ID
|
||||||
|
key -- Key to get/set
|
||||||
|
delete -- Delete the key
|
||||||
|
|
||||||
Keyword arguments:
|
|
||||||
domain -- The domain name
|
|
||||||
"""
|
"""
|
||||||
return _load_domain_settings()
|
|
||||||
|
|
||||||
|
domains = _load_domain_settings()
|
||||||
|
if not domain in domains.keys():
|
||||||
|
# TODO add locales
|
||||||
|
raise YunohostError("domain_name_unknown", domain=domain)
|
||||||
|
|
||||||
def domain_config_show(domain):
|
domain_settings = _get_domain_settings(domain, False) or {}
|
||||||
"""
|
|
||||||
Show settings of a domain
|
|
||||||
|
|
||||||
Keyword arguments:
|
# GET
|
||||||
domain -- The domain name
|
if value is None and not delete:
|
||||||
"""
|
return domain_settings.get(key, None)
|
||||||
return _get_domain_settings(domain, False)
|
|
||||||
|
|
||||||
|
# DELETE
|
||||||
|
if delete:
|
||||||
|
if key in domain_settings:
|
||||||
|
del domain_settings[key]
|
||||||
|
|
||||||
def domain_config_get(domain, key):
|
# SET
|
||||||
"""
|
else:
|
||||||
Show a setting of a domain
|
|
||||||
|
|
||||||
Keyword arguments:
|
if "ttl" == key:
|
||||||
domain -- The domain name
|
try:
|
||||||
key -- ttl, xmpp, mail, owned_dns_zone
|
ttl = int(value)
|
||||||
"""
|
except:
|
||||||
settings = _get_domain_settings(domain, False)
|
# TODO add locales
|
||||||
return settings[domain][key]
|
raise YunohostError("bad_value_type", value_type=type(ttl))
|
||||||
|
|
||||||
|
if ttl < 0:
|
||||||
|
# TODO add locales
|
||||||
|
raise YunohostError("must_be_positive", value_type=type(ttl))
|
||||||
|
domain_settings[key] = value
|
||||||
|
|
||||||
def _get_domain_settings(domain, subdomains):
|
def _get_domain_settings(domain, subdomains):
|
||||||
"""
|
"""
|
||||||
|
@ -786,55 +796,22 @@ def _get_domain_settings(domain, subdomains):
|
||||||
return only_wanted_domains
|
return only_wanted_domains
|
||||||
|
|
||||||
|
|
||||||
def domain_config_set(domain, key, value):
|
def _set_domain_settings(domain, domain_settings):
|
||||||
#(domain, ttl=None, xmpp=None, mail=None, owned_dns_zone=None):
|
|
||||||
"""
|
"""
|
||||||
Set some settings of a domain, for DNS generation.
|
Set settings of a domain
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
domain -- The domain name
|
domain -- The domain name
|
||||||
key must be one of this strings:
|
settings -- Dict with doamin settings
|
||||||
ttl -- the Time To Live for this domains DNS record
|
|
||||||
xmpp -- configure XMPP DNS records for this domain
|
|
||||||
mail -- configure mail DNS records for this domain
|
|
||||||
owned_dns_zone -- is this domain DNS zone owned? (is it a full domain or a subdomain?)
|
|
||||||
value must be set according to the key
|
|
||||||
"""
|
"""
|
||||||
domains = _load_domain_settings()
|
domains = _load_domain_settings()
|
||||||
|
|
||||||
if not domain in domains.keys():
|
if not domain in domains.keys():
|
||||||
# TODO add locales
|
|
||||||
raise YunohostError("domain_name_unknown", domain=domain)
|
raise YunohostError("domain_name_unknown", domain=domain)
|
||||||
|
|
||||||
if "ttl" == key:
|
domains[domain] = domain_settings
|
||||||
try:
|
|
||||||
ttl = int(value)
|
|
||||||
except:
|
|
||||||
# TODO add locales
|
|
||||||
raise YunohostError("bad_value_type", value_type=type(ttl))
|
|
||||||
|
|
||||||
if ttl < 0:
|
|
||||||
# TODO add locales
|
|
||||||
raise YunohostError("must_be_positive", value_type=type(ttl))
|
|
||||||
|
|
||||||
domains[domain]["ttl"] = ttl
|
|
||||||
|
|
||||||
elif "xmpp" == key:
|
|
||||||
domains[domain]["xmpp"] = value in ["True", "true", "1"]
|
|
||||||
|
|
||||||
elif "mail" == key:
|
|
||||||
domains[domain]["mail"] = value in ["True", "true", "1"]
|
|
||||||
|
|
||||||
elif "owned_dns_zone" == key:
|
|
||||||
domains[domain]["owned_dns_zone"] = value in ["True", "true", "1"]
|
|
||||||
|
|
||||||
else:
|
|
||||||
# TODO add locales
|
|
||||||
raise YunohostError("no_setting_given")
|
|
||||||
|
|
||||||
# Save the settings to the .yaml file
|
# Save the settings to the .yaml file
|
||||||
with open(DOMAIN_SETTINGS_PATH, 'w') as file:
|
with open(DOMAIN_SETTINGS_PATH, 'w') as file:
|
||||||
yaml.dump(domains, file)
|
yaml.dump(domains, file, default_flow_style=False)
|
||||||
|
|
||||||
return domains[domain]
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue