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
|
||||
path:
|
||||
help: The path to check (e.g. /coffee)
|
||||
|
||||
subcategories:
|
||||
config:
|
||||
subcategory_help: Domains DNS settings
|
||||
actions:
|
||||
# domain_config_list
|
||||
list:
|
||||
action_help: Get settings for all domains
|
||||
api: GET /domains/list
|
||||
|
||||
# domain_config_show
|
||||
show:
|
||||
action_help: Get settings for all domains
|
||||
api: GET /domains/<domain>/show
|
||||
arguments:
|
||||
domain:
|
||||
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_setting()
|
||||
setting:
|
||||
action_help: Set or get an app setting value
|
||||
api: GET /domains/<domain>/settings
|
||||
arguments:
|
||||
domain:
|
||||
help: Domaine name
|
||||
key:
|
||||
help: Key to get/set
|
||||
-v:
|
||||
full: --value
|
||||
help: Value to set
|
||||
-d:
|
||||
full: --delete
|
||||
help: Delete the key
|
||||
action: store_true
|
||||
|
||||
|
||||
### domain_info()
|
||||
|
|
|
@ -728,38 +728,48 @@ def _load_domain_settings():
|
|||
|
||||
return new_domains
|
||||
|
||||
|
||||
def domain_config_list():
|
||||
def domain_setting(domain, key, value=None, delete=False):
|
||||
"""
|
||||
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)
|
||||
|
||||
domain_settings = _get_domain_settings(domain, False) or {}
|
||||
|
||||
def domain_config_show(domain):
|
||||
"""
|
||||
Show settings of a domain
|
||||
# GET
|
||||
if value is None and not delete:
|
||||
return domain_settings.get(key, None)
|
||||
|
||||
Keyword arguments:
|
||||
domain -- The domain name
|
||||
"""
|
||||
return _get_domain_settings(domain, False)
|
||||
# DELETE
|
||||
if delete:
|
||||
if key in domain_settings:
|
||||
del domain_settings[key]
|
||||
|
||||
# SET
|
||||
else:
|
||||
|
||||
if "ttl" == key:
|
||||
try:
|
||||
ttl = int(value)
|
||||
except:
|
||||
# TODO add locales
|
||||
raise YunohostError("bad_value_type", value_type=type(ttl))
|
||||
|
||||
def domain_config_get(domain, key):
|
||||
"""
|
||||
Show a setting of a domain
|
||||
|
||||
Keyword arguments:
|
||||
domain -- The domain name
|
||||
key -- ttl, xmpp, mail, owned_dns_zone
|
||||
"""
|
||||
settings = _get_domain_settings(domain, False)
|
||||
return settings[domain][key]
|
||||
|
||||
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):
|
||||
"""
|
||||
|
@ -786,55 +796,22 @@ def _get_domain_settings(domain, subdomains):
|
|||
return only_wanted_domains
|
||||
|
||||
|
||||
def domain_config_set(domain, key, value):
|
||||
#(domain, ttl=None, xmpp=None, mail=None, owned_dns_zone=None):
|
||||
def _set_domain_settings(domain, domain_settings):
|
||||
"""
|
||||
Set some settings of a domain, for DNS generation.
|
||||
Set settings of a domain
|
||||
|
||||
Keyword arguments:
|
||||
domain -- The domain name
|
||||
key must be one of this strings:
|
||||
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
|
||||
settings -- Dict with doamin settings
|
||||
|
||||
"""
|
||||
domains = _load_domain_settings()
|
||||
|
||||
if not domain in domains.keys():
|
||||
# TODO add locales
|
||||
raise YunohostError("domain_name_unknown", domain=domain)
|
||||
|
||||
if "ttl" == key:
|
||||
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")
|
||||
domains[domain] = domain_settings
|
||||
|
||||
# Save the settings to the .yaml file
|
||||
with open(DOMAIN_SETTINGS_PATH, 'w') as file:
|
||||
yaml.dump(domains, file)
|
||||
|
||||
return domains[domain]
|
||||
yaml.dump(domains, file, default_flow_style=False)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue