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()
|
||||
info:
|
||||
action_help: Get domains aggredated data
|
||||
action_help: Get domain aggredated data
|
||||
api: GET /domains/<domains>
|
||||
arguments:
|
||||
domains:
|
||||
help: Domains to check
|
||||
nargs: "*"
|
||||
domain:
|
||||
help: Domain to check
|
||||
extra:
|
||||
pattern: *pattern_domain
|
||||
|
||||
### domain_add()
|
||||
add:
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"""
|
||||
import os
|
||||
from typing import List, Any
|
||||
from collections import OrderedDict
|
||||
|
||||
from moulinette import m18n, Moulinette
|
||||
from moulinette.core import MoulinetteError
|
||||
|
@ -99,7 +100,6 @@ def domain_list(exclude_subdomains=False, tree=False):
|
|||
tree -- Display domains as a hierarchy tree
|
||||
|
||||
"""
|
||||
from collections import OrderedDict
|
||||
|
||||
domains = _get_domains(exclude_subdomains)
|
||||
main = _get_maindomain()
|
||||
|
@ -128,80 +128,37 @@ def domain_list(exclude_subdomains=False, tree=False):
|
|||
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:
|
||||
domains -- Domains to be checked
|
||||
|
||||
domain -- Domain to be checked
|
||||
"""
|
||||
|
||||
from collections import OrderedDict
|
||||
from yunohost.app import app_info
|
||||
from yunohost.dns import _get_registar_settings
|
||||
from yunohost.utils.dns import is_special_use_tld
|
||||
|
||||
# If no domains given, consider all yunohost domains
|
||||
if domains == []:
|
||||
domains = _get_domains()
|
||||
# Else, validate that yunohost knows the domains given
|
||||
else:
|
||||
for domain in domains:
|
||||
_assert_domain_exists(domain)
|
||||
_assert_domain_exists(domain)
|
||||
|
||||
def get_dns_config(domain):
|
||||
if is_special_use_tld(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}
|
||||
registrar, _ = _get_registar_settings(domain)
|
||||
certificate = domain_cert_status([domain], full=True)["certificates"][domain]
|
||||
|
||||
apps = []
|
||||
for app in _installed_apps():
|
||||
settings = _get_app_settings(app)
|
||||
if settings["domain"] in domains:
|
||||
apps[settings["domain"]].append(
|
||||
if settings.get("domain") == domain:
|
||||
apps.append(
|
||||
{"name": app_info(app)["name"], "id": app, "path": settings["path"]}
|
||||
)
|
||||
|
||||
result = OrderedDict()
|
||||
for domain in domains:
|
||||
result[domain] = OrderedDict(
|
||||
{
|
||||
"certificate": {
|
||||
"authority": certs[domain]["CA_type"]["code"],
|
||||
"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}
|
||||
return {
|
||||
"certificate": certificate,
|
||||
"registrar": registrar,
|
||||
"apps": apps,
|
||||
"main": _get_maindomain() == domain,
|
||||
# TODO : add parent / child domains ?
|
||||
}
|
||||
|
||||
|
||||
def _assert_domain_exists(domain):
|
||||
|
|
Loading…
Add table
Reference in a new issue