mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[yolo] Use read_json / write_to_json helpers to read/write ssowat conf.json.persistent
This commit is contained in:
parent
7d0119ade4
commit
6dc720f3cf
4 changed files with 22 additions and 39 deletions
|
@ -508,8 +508,6 @@
|
||||||
"service_unknown": "Unknown service '{service:s}'",
|
"service_unknown": "Unknown service '{service:s}'",
|
||||||
"ssowat_conf_generated": "SSOwat configuration generated",
|
"ssowat_conf_generated": "SSOwat configuration generated",
|
||||||
"ssowat_conf_updated": "SSOwat configuration updated",
|
"ssowat_conf_updated": "SSOwat configuration updated",
|
||||||
"ssowat_persistent_conf_read_error": "Could not read persistent SSOwat configuration: {error:s}. Edit /etc/ssowat/conf.json.persistent file to fix the JSON syntax",
|
|
||||||
"ssowat_persistent_conf_write_error": "Could not save persistent SSOwat configuration: {error:s}. Edit /etc/ssowat/conf.json.persistent file to fix the JSON syntax",
|
|
||||||
"system_upgraded": "System upgraded",
|
"system_upgraded": "System upgraded",
|
||||||
"system_username_exists": "Username already exists in the list of system users",
|
"system_username_exists": "Username already exists in the list of system users",
|
||||||
"this_action_broke_dpkg": "This action broke dpkg/APT (the system package managers)… You can try to solve this issue by connecting through SSH and running `sudo dpkg --configure -a`.",
|
"this_action_broke_dpkg": "This action broke dpkg/APT (the system package managers)… You can try to solve this issue by connecting through SSH and running `sudo dpkg --configure -a`.",
|
||||||
|
|
|
@ -41,7 +41,7 @@ from datetime import datetime
|
||||||
|
|
||||||
from moulinette import msignals, m18n, msettings
|
from moulinette import msignals, m18n, msettings
|
||||||
from moulinette.utils.log import getActionLogger
|
from moulinette.utils.log import getActionLogger
|
||||||
from moulinette.utils.filesystem import read_json, read_toml
|
from moulinette.utils.filesystem import read_json, read_toml, write_to_json
|
||||||
|
|
||||||
from yunohost.service import service_log, service_status, _run_service_command
|
from yunohost.service import service_log, service_status, _run_service_command
|
||||||
from yunohost.utils import packages
|
from yunohost.utils import packages
|
||||||
|
@ -1233,25 +1233,21 @@ def app_makedefault(operation_logger, app, domain=None):
|
||||||
raise YunohostError('app_make_default_location_already_used', app=app, domain=app_domain,
|
raise YunohostError('app_make_default_location_already_used', app=app, domain=app_domain,
|
||||||
other_app=app_map(raw=True)[domain]["/"]["id"])
|
other_app=app_map(raw=True)[domain]["/"]["id"])
|
||||||
|
|
||||||
try:
|
# TODO / FIXME : current trick is to add this to conf.json.persisten
|
||||||
with open('/etc/ssowat/conf.json.persistent') as json_conf:
|
# This is really not robust and should be improved
|
||||||
ssowat_conf = json.loads(str(json_conf.read()))
|
# e.g. have a flag in /etc/yunohost/apps/$app/ to say that this is the
|
||||||
except ValueError as e:
|
# default app or idk...
|
||||||
raise YunohostError('ssowat_persistent_conf_read_error', error=e)
|
if not os.path.exists('/etc/ssowat/conf.json.persistent'):
|
||||||
except IOError:
|
|
||||||
ssowat_conf = {}
|
ssowat_conf = {}
|
||||||
|
else:
|
||||||
|
ssowat_conf = read_json('/etc/ssowat/conf.json.persistent')
|
||||||
|
|
||||||
if 'redirected_urls' not in ssowat_conf:
|
if 'redirected_urls' not in ssowat_conf:
|
||||||
ssowat_conf['redirected_urls'] = {}
|
ssowat_conf['redirected_urls'] = {}
|
||||||
|
|
||||||
ssowat_conf['redirected_urls'][domain + '/'] = app_domain + app_path
|
ssowat_conf['redirected_urls'][domain + '/'] = app_domain + app_path
|
||||||
|
|
||||||
try:
|
write_to_json('/etc/ssowat/conf.json.persistent', ssowat_conf)
|
||||||
with open('/etc/ssowat/conf.json.persistent', 'w+') as f:
|
|
||||||
json.dump(ssowat_conf, f, sort_keys=True, indent=4)
|
|
||||||
except IOError as e:
|
|
||||||
raise YunohostError('ssowat_persistent_conf_write_error', error=e)
|
|
||||||
|
|
||||||
os.system('chmod 644 /etc/ssowat/conf.json.persistent')
|
os.system('chmod 644 /etc/ssowat/conf.json.persistent')
|
||||||
|
|
||||||
logger.success(m18n.n('ssowat_conf_updated'))
|
logger.success(m18n.n('ssowat_conf_updated'))
|
||||||
|
|
|
@ -350,25 +350,17 @@ def tools_postinstall(operation_logger, domain, password, ignore_dyndns=False,
|
||||||
os.system('hostname yunohost.yunohost.org')
|
os.system('hostname yunohost.yunohost.org')
|
||||||
|
|
||||||
# Add a temporary SSOwat rule to redirect SSO to admin page
|
# Add a temporary SSOwat rule to redirect SSO to admin page
|
||||||
try:
|
if not os.path.exists('/etc/ssowat/conf.json.persistent'):
|
||||||
with open('/etc/ssowat/conf.json.persistent') as json_conf:
|
|
||||||
ssowat_conf = json.loads(str(json_conf.read()))
|
|
||||||
except ValueError as e:
|
|
||||||
raise YunohostError('ssowat_persistent_conf_read_error', error=str(e))
|
|
||||||
except IOError:
|
|
||||||
ssowat_conf = {}
|
ssowat_conf = {}
|
||||||
|
else:
|
||||||
|
ssowat_conf = read_json('/etc/ssowat/conf.json.persistent')
|
||||||
|
|
||||||
if 'redirected_urls' not in ssowat_conf:
|
if 'redirected_urls' not in ssowat_conf:
|
||||||
ssowat_conf['redirected_urls'] = {}
|
ssowat_conf['redirected_urls'] = {}
|
||||||
|
|
||||||
ssowat_conf['redirected_urls']['/'] = domain + '/yunohost/admin'
|
ssowat_conf['redirected_urls']['/'] = domain + '/yunohost/admin'
|
||||||
|
|
||||||
try:
|
write_to_json('/etc/ssowat/conf.json.persistent', ssowat_conf)
|
||||||
with open('/etc/ssowat/conf.json.persistent', 'w+') as f:
|
|
||||||
json.dump(ssowat_conf, f, sort_keys=True, indent=4)
|
|
||||||
except IOError as e:
|
|
||||||
raise YunohostError('ssowat_persistent_conf_write_error', error=str(e))
|
|
||||||
|
|
||||||
os.system('chmod 644 /etc/ssowat/conf.json.persistent')
|
os.system('chmod 644 /etc/ssowat/conf.json.persistent')
|
||||||
|
|
||||||
# Create SSL CA
|
# Create SSL CA
|
||||||
|
|
|
@ -35,8 +35,10 @@ import subprocess
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from moulinette import m18n
|
from moulinette import m18n
|
||||||
from yunohost.utils.error import YunohostError
|
|
||||||
from moulinette.utils.log import getActionLogger
|
from moulinette.utils.log import getActionLogger
|
||||||
|
from moulinette.utils.filesystem import read_json, write_to_json, read_yaml, write_to_yaml
|
||||||
|
|
||||||
|
from yunohost.utils.error import YunohostError
|
||||||
from yunohost.service import service_status
|
from yunohost.service import service_status
|
||||||
from yunohost.log import is_unit_operation
|
from yunohost.log import is_unit_operation
|
||||||
|
|
||||||
|
@ -195,21 +197,16 @@ def user_create(operation_logger, username, firstname, lastname, mail, password,
|
||||||
attr_dict['mail'] = [attr_dict['mail']] + aliases
|
attr_dict['mail'] = [attr_dict['mail']] + aliases
|
||||||
|
|
||||||
# If exists, remove the redirection from the SSO
|
# If exists, remove the redirection from the SSO
|
||||||
try:
|
if not os.path.exists('/etc/ssowat/conf.json.persistent'):
|
||||||
with open('/etc/ssowat/conf.json.persistent') as json_conf:
|
|
||||||
ssowat_conf = json.loads(str(json_conf.read()))
|
|
||||||
except ValueError as e:
|
|
||||||
raise YunohostError('ssowat_persistent_conf_read_error', error=str(e))
|
|
||||||
except IOError:
|
|
||||||
ssowat_conf = {}
|
ssowat_conf = {}
|
||||||
|
else:
|
||||||
|
ssowat_conf = read_json('/etc/ssowat/conf.json.persistent')
|
||||||
|
|
||||||
if 'redirected_urls' in ssowat_conf and '/' in ssowat_conf['redirected_urls']:
|
if 'redirected_urls' in ssowat_conf and '/' in ssowat_conf['redirected_urls']:
|
||||||
del ssowat_conf['redirected_urls']['/']
|
del ssowat_conf['redirected_urls']['/']
|
||||||
try:
|
|
||||||
with open('/etc/ssowat/conf.json.persistent', 'w+') as f:
|
write_to_json('/etc/ssowat/conf.json.persistent', ssowat_conf)
|
||||||
json.dump(ssowat_conf, f, sort_keys=True, indent=4)
|
os.system('chmod 644 /etc/ssowat/conf.json.persistent')
|
||||||
except IOError as e:
|
|
||||||
raise YunohostError('ssowat_persistent_conf_write_error', error=str(e))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ldap.add('uid=%s,ou=users' % username, attr_dict)
|
ldap.add('uid=%s,ou=users' % username, attr_dict)
|
||||||
|
|
Loading…
Add table
Reference in a new issue