Change API naming etc. Expect a new change to come!

This commit is contained in:
Paco 2021-03-22 01:57:20 +01:00
parent f295dffd00
commit fa818a476a
2 changed files with 92 additions and 69 deletions

View file

@ -460,31 +460,6 @@ domain:
help: Do not ask confirmation to remove apps help: Do not ask confirmation to remove apps
action: store_true action: store_true
settings:
action_help: Get settings for a domain
api: GET /domains/<domain>/settings
arguments:
domain:
help: Target domain
set-settings:
action_help: Set settings of a domain
api: POST /domains/<domain>/settings
arguments:
domain:
help: Target domain
-t:
full: --ttl
help: Time To Live of this domain's DNS records
-x:
full: --xmpp
help: Configure XMPP in this domain's DNS records? True or False
-m:
full: --mail
help: Configure mail in this domain's DNS records? True or False
-o:
full: --owned-dns-zone
help: Is this domain owned as a DNS zone? Is it a full domain, i.e not a subdomain? True or False
### domain_dns_conf() ### domain_dns_conf()
dns-conf: dns-conf:
@ -493,6 +468,8 @@ domain:
arguments: arguments:
domain: domain:
help: Target domain help: Target domain
extra:
pattern: *pattern_domain
### domain_maindomain() ### domain_maindomain()
main-domain: main-domain:
@ -575,6 +552,62 @@ domain:
path: path:
help: The path to check (e.g. /coffee) 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
arguments:
domain:
help: Target domain
extra:
pattern: *pattern_domain
# 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_info() ### domain_info()
# info: # info:

View file

@ -705,10 +705,8 @@ def _load_domain_settings():
is_maindomain = domain == maindomain is_maindomain = domain == maindomain
domain_in_old_domains = domain in old_domains.keys() domain_in_old_domains = domain in old_domains.keys()
# Update each setting if not present # Update each setting if not present
new_domains[domain] = { new_domains[domain] = {}
# Set "main" value # new_domains[domain] = { "main": is_maindomain }
"main": is_maindomain
}
# Set other values (default value if missing) # Set other values (default value if missing)
for setting, default in [ ("xmpp", is_maindomain), ("mail", is_maindomain), ("owned_dns_zone", True), ("ttl", 3600) ]: for setting, default in [ ("xmpp", is_maindomain), ("mail", is_maindomain), ("owned_dns_zone", True), ("ttl", 3600) ]:
if domain_in_old_domains and setting in old_domains[domain].keys(): if domain_in_old_domains and setting in old_domains[domain].keys():
@ -719,9 +717,9 @@ def _load_domain_settings():
return new_domains return new_domains
def domain_settings(domain): def domain_config_show(domain):
""" """
Get settings of a domain Show settings of a domain
Keyword arguments: Keyword arguments:
domain -- The domain name domain -- The domain name
@ -729,6 +727,18 @@ def domain_settings(domain):
return _get_domain_settings(domain, False) return _get_domain_settings(domain, False)
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]
def _get_domain_settings(domain, subdomains): def _get_domain_settings(domain, subdomains):
""" """
Get settings of a domain Get settings of a domain
@ -740,7 +750,7 @@ def _get_domain_settings(domain, subdomains):
""" """
domains = _load_domain_settings() domains = _load_domain_settings()
if not domain in domains.keys(): if not domain in domains.keys():
return {} raise YunohostError("domain_name_unknown", domain=domain)
only_wanted_domains = dict() only_wanted_domains = dict()
for entry in domains.keys(): for entry in domains.keys():
@ -754,16 +764,19 @@ def _get_domain_settings(domain, subdomains):
return only_wanted_domains return only_wanted_domains
def domain_set_settings(domain, ttl=None, xmpp=None, mail=None, owned_dns_zone=None): def domain_config_set(domain, key, value):
#(domain, ttl=None, xmpp=None, mail=None, owned_dns_zone=None):
""" """
Set some settings of a domain, for DNS generation. Set some settings of a domain, for DNS generation.
Keyword arguments: Keyword arguments:
domain -- The domain name domain -- The domain name
--ttl -- the Time To Live for this domains DNS record key must be one of this strings:
--xmpp -- configure XMPP DNS records for this domain ttl -- the Time To Live for this domains DNS record
--mail -- configure mail DNS records for this domain xmpp -- configure XMPP DNS records for this domain
--owned_dns_zone -- is this domain DNS zone owned? (is it a full domain or a subdomain?) 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()
@ -771,11 +784,9 @@ def domain_set_settings(domain, ttl=None, xmpp=None, mail=None, owned_dns_zone=N
# TODO add locales # TODO add locales
raise YunohostError("domain_name_unknown", domain=domain) raise YunohostError("domain_name_unknown", domain=domain)
setting_set = False if "ttl" == key:
if ttl is not None:
try: try:
ttl = int(ttl) ttl = int(value)
except: except:
# TODO add locales # TODO add locales
raise YunohostError("bad_value_type", value_type=type(ttl)) raise YunohostError("bad_value_type", value_type=type(ttl))
@ -785,38 +796,17 @@ def domain_set_settings(domain, ttl=None, xmpp=None, mail=None, owned_dns_zone=N
raise YunohostError("must_be_positive", value_type=type(ttl)) raise YunohostError("must_be_positive", value_type=type(ttl))
domains[domain]["ttl"] = ttl domains[domain]["ttl"] = ttl
setting_set = True
if xmpp is not None: elif "xmpp" == key:
try: domains[domain]["xmpp"] = value in ["True", "true", "1"]
xmpp = xmpp in ["True", "true", "1"]
except:
# TODO add locales
raise YunohostError("bad_value_type", value_type=type(xmpp))
domains[domain]["xmpp"] = xmpp
setting_set = True
if mail is not None: elif "mail" == key:
try: domains[domain]["mail"] = value in ["True", "true", "1"]
mail = mail in ["True", "true", "1"]
except:
# TODO add locales
raise YunohostError("bad_value_type", value_type=type(mail))
domains[domain]["mail"] = mail elif "owned_dns_zone" == key:
setting_set = True domains[domain]["owned_dns_zone"] = value in ["True", "true", "1"]
if owned_dns_zone is not None: else:
try:
owned_dns_zone = owned_dns_zone in ["True", "true", "1"]
except:
# TODO add locales
raise YunohostError("bad_value_type", value_type=type(owned_dns_zone))
domains[domain]["owned_dns_zone"] = owned_dns_zone
setting_set = True
if not setting_set:
# TODO add locales # TODO add locales
raise YunohostError("no_setting_given") raise YunohostError("no_setting_given")