mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Rework domain_info
This commit is contained in:
parent
81b90d79cb
commit
96233ea600
2 changed files with 22 additions and 64 deletions
|
@ -449,12 +449,13 @@ domain:
|
||||||
|
|
||||||
### domain_info()
|
### domain_info()
|
||||||
info:
|
info:
|
||||||
action_help: Get domains aggredated data
|
action_help: Get domain aggredated data
|
||||||
api: GET /domains/<domains>
|
api: GET /domains/<domains>
|
||||||
arguments:
|
arguments:
|
||||||
domains:
|
domain:
|
||||||
help: Domains to check
|
help: Domain to check
|
||||||
nargs: "*"
|
extra:
|
||||||
|
pattern: *pattern_domain
|
||||||
|
|
||||||
### domain_add()
|
### domain_add()
|
||||||
add:
|
add:
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
from moulinette import m18n, Moulinette
|
from moulinette import m18n, Moulinette
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
|
@ -99,7 +100,6 @@ def domain_list(exclude_subdomains=False, tree=False):
|
||||||
tree -- Display domains as a hierarchy tree
|
tree -- Display domains as a hierarchy tree
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
domains = _get_domains(exclude_subdomains)
|
domains = _get_domains(exclude_subdomains)
|
||||||
main = _get_maindomain()
|
main = _get_maindomain()
|
||||||
|
@ -128,80 +128,37 @@ def domain_list(exclude_subdomains=False, tree=False):
|
||||||
return {"domains": result, "main": main}
|
return {"domains": result, "main": main}
|
||||||
|
|
||||||
|
|
||||||
def domain_info(domains):
|
def domain_info(domain):
|
||||||
"""
|
"""
|
||||||
Print aggregate data about domains (all by default)
|
Print aggregate data for a specific domain
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
domains -- Domains to be checked
|
domain -- Domain to be checked
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from collections import OrderedDict
|
|
||||||
from yunohost.app import app_info
|
from yunohost.app import app_info
|
||||||
from yunohost.dns import _get_registar_settings
|
from yunohost.dns import _get_registar_settings
|
||||||
from yunohost.utils.dns import is_special_use_tld
|
|
||||||
|
|
||||||
# If no domains given, consider all yunohost domains
|
_assert_domain_exists(domain)
|
||||||
if domains == []:
|
|
||||||
domains = _get_domains()
|
|
||||||
# Else, validate that yunohost knows the domains given
|
|
||||||
else:
|
|
||||||
for domain in domains:
|
|
||||||
_assert_domain_exists(domain)
|
|
||||||
|
|
||||||
def get_dns_config(domain):
|
registrar, _ = _get_registar_settings(domain)
|
||||||
if is_special_use_tld(domain):
|
certificate = domain_cert_status([domain], full=True)["certificates"][domain]
|
||||||
return {"method": "none"}
|
|
||||||
|
|
||||||
registrar, registrar_credentials = _get_registar_settings(domain)
|
|
||||||
|
|
||||||
if not registrar or registrar == "None": # yes it's None as a string
|
|
||||||
return {"method": "manual", "semi_auto_status": "unavailable"}
|
|
||||||
if registrar == "parent_domain":
|
|
||||||
return {"method": "handled_in_parent"}
|
|
||||||
if registrar == "yunohost":
|
|
||||||
return {"method": "auto", "registrar": registrar}
|
|
||||||
if not all(registrar_credentials.values()):
|
|
||||||
return {
|
|
||||||
"method": "manual",
|
|
||||||
"semi_auto_status": "activable",
|
|
||||||
"registrar": registrar,
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"method": "semi_auto",
|
|
||||||
"registrar": registrar,
|
|
||||||
"semi_auto_status": "activated",
|
|
||||||
}
|
|
||||||
|
|
||||||
certs = domain_cert_status(domains, full=True)["certificates"]
|
|
||||||
apps = {domain: [] for domain in domains}
|
|
||||||
|
|
||||||
|
apps = []
|
||||||
for app in _installed_apps():
|
for app in _installed_apps():
|
||||||
settings = _get_app_settings(app)
|
settings = _get_app_settings(app)
|
||||||
if settings["domain"] in domains:
|
if settings.get("domain") == domain:
|
||||||
apps[settings["domain"]].append(
|
apps.append(
|
||||||
{"name": app_info(app)["name"], "id": app, "path": settings["path"]}
|
{"name": app_info(app)["name"], "id": app, "path": settings["path"]}
|
||||||
)
|
)
|
||||||
|
|
||||||
result = OrderedDict()
|
return {
|
||||||
for domain in domains:
|
"certificate": certificate,
|
||||||
result[domain] = OrderedDict(
|
"registrar": registrar,
|
||||||
{
|
"apps": apps,
|
||||||
"certificate": {
|
"main": _get_maindomain() == domain,
|
||||||
"authority": certs[domain]["CA_type"]["code"],
|
# TODO : add parent / child domains ?
|
||||||
"validity": certs[domain]["validity"],
|
}
|
||||||
"acme_status": certs[domain]["acme_status"],
|
|
||||||
},
|
|
||||||
"dns": get_dns_config(domain),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if apps[domain]:
|
|
||||||
result[domain]["apps"] = apps[domain]
|
|
||||||
|
|
||||||
return {"domains": result}
|
|
||||||
|
|
||||||
|
|
||||||
def _assert_domain_exists(domain):
|
def _assert_domain_exists(domain):
|
||||||
|
|
Loading…
Add table
Reference in a new issue