[ux] move 'maindomain' command from 'tools' to 'domain' section

This commit is contained in:
Laurent Peuch 2019-09-11 04:31:22 +02:00
parent 3bc4945ccf
commit 877cfc1fe5
3 changed files with 75 additions and 53 deletions

View file

@ -441,6 +441,19 @@ domain:
- !!str ^[0-9]+$
- "pattern_positive_number"
### domain_maindomain()
maindomain:
action_help: Check the current main domain, or change it
api:
- GET /domains/main
- PUT /domains/main
arguments:
-n:
full: --new-main-domain
help: Change the current main domain
extra:
pattern: *pattern_domain
### certificate_status()
cert-status:
action_help: List status of current certificates (all by default).
@ -1542,6 +1555,7 @@ tools:
### tools_maindomain()
maindomain:
action_help: Check the current main domain, or change it
deprecated: true
api:
- GET /domains/main
- PUT /domains/main

View file

@ -34,10 +34,12 @@ from moulinette.utils.log import getActionLogger
import yunohost.certificate
from yunohost.app import app_ssowatconf
from yunohost.regenconf import regen_conf
from yunohost.utils.network import get_public_ip
from yunohost.log import is_unit_operation
from yunohost.hook import hook_callback
from yunohost.tools import _set_hostname
logger = getActionLogger('yunohost.domain')
@ -233,6 +235,62 @@ def domain_dns_conf(domain, ttl=None):
return result
@is_unit_operation()
def domain_maindomain(operation_logger, new_main_domain=None):
"""
Check the current main domain, or change it
Keyword argument:
new_main_domain -- The new domain to be set as the main domain
"""
# If no new domain specified, we return the current main domain
if not new_main_domain:
return {'current_main_domain': _get_maindomain()}
# Check domain exists
if new_main_domain not in domain_list()['domains']:
raise YunohostError('domain_unknown')
operation_logger.related_to.append(('domain', new_main_domain))
operation_logger.start()
# Apply changes to ssl certs
ssl_key = "/etc/ssl/private/yunohost_key.pem"
ssl_crt = "/etc/ssl/private/yunohost_crt.pem"
new_ssl_key = "/etc/yunohost/certs/%s/key.pem" % new_main_domain
new_ssl_crt = "/etc/yunohost/certs/%s/crt.pem" % new_main_domain
try:
if os.path.exists(ssl_key) or os.path.lexists(ssl_key):
os.remove(ssl_key)
if os.path.exists(ssl_crt) or os.path.lexists(ssl_crt):
os.remove(ssl_crt)
os.symlink(new_ssl_key, ssl_key)
os.symlink(new_ssl_crt, ssl_crt)
_set_maindomain(new_main_domain)
except Exception as e:
logger.warning("%s" % e, exc_info=1)
raise YunohostError('maindomain_change_failed')
_set_hostname(new_main_domain)
# Generate SSOwat configuration file
app_ssowatconf()
# Regen configurations
try:
with open('/etc/yunohost/installed', 'r'):
regen_conf()
except IOError:
pass
logger.success(m18n.n('maindomain_changed'))
def domain_cert_status(domain_list, full=False):
return yunohost.certificate.certificate_status(domain_list, full)

View file

@ -39,7 +39,7 @@ from moulinette.utils.log import getActionLogger
from moulinette.utils.process import check_output, call_async_output
from moulinette.utils.filesystem import read_json, write_to_json, read_yaml, write_to_yaml
from yunohost.app import app_fetchlist, app_info, app_upgrade, app_ssowatconf, app_list, _install_appslist_fetch_cron
from yunohost.domain import domain_add, domain_list, _get_maindomain, _set_maindomain
from yunohost.domain import domain_add, domain_list
from yunohost.dyndns import _dyndns_available, _dyndns_provides
from yunohost.firewall import firewall_upnp
from yunohost.service import service_status, service_start, service_enable
@ -166,58 +166,8 @@ def tools_adminpw(new_password, check_strength=True):
@is_unit_operation()
def tools_maindomain(operation_logger, new_main_domain=None):
"""
Check the current main domain, or change it
Keyword argument:
new_domain -- The new domain to be set as the main domain
"""
# If no new domain specified, we return the current main domain
if not new_domain:
return {'current_main_domain': _get_maindomain()}
# Check domain exists
if new_domain not in domain_list()['domains']:
raise YunohostError('domain_unknown')
operation_logger.related_to.append(('domain', new_domain))
operation_logger.start()
# Apply changes to ssl certs
ssl_key = "/etc/ssl/private/yunohost_key.pem"
ssl_crt = "/etc/ssl/private/yunohost_crt.pem"
new_ssl_key = "/etc/yunohost/certs/%s/key.pem" % new_domain
new_ssl_crt = "/etc/yunohost/certs/%s/crt.pem" % new_domain
try:
if os.path.exists(ssl_key) or os.path.lexists(ssl_key):
os.remove(ssl_key)
if os.path.exists(ssl_crt) or os.path.lexists(ssl_crt):
os.remove(ssl_crt)
os.symlink(new_ssl_key, ssl_key)
os.symlink(new_ssl_crt, ssl_crt)
_set_maindomain(new_domain)
except Exception as e:
logger.warning("%s" % e, exc_info=1)
raise YunohostError('maindomain_change_failed')
_set_hostname(new_domain)
# Generate SSOwat configuration file
app_ssowatconf()
# Regen configurations
try:
with open('/etc/yunohost/installed', 'r'):
regen_conf()
except IOError:
pass
logger.success(m18n.n('maindomain_changed'))
from yunohost.domain import domain_maindomain
return domain_main_domain(new_main_domain=new_main_domain)
def _set_hostname(hostname, pretty_hostname=None):