mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
settings: use the yml when necessary
This commit is contained in:
parent
0bad639b3d
commit
2d92c93af1
2 changed files with 12 additions and 10 deletions
|
@ -2,10 +2,13 @@ import subprocess
|
||||||
import time
|
import time
|
||||||
import urllib
|
import urllib
|
||||||
import os
|
import os
|
||||||
import json
|
|
||||||
|
|
||||||
from yunohost.utils.error import YunohostError
|
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_yaml
|
||||||
|
)
|
||||||
|
|
||||||
from yunohost.tools import Migration
|
from yunohost.tools import Migration
|
||||||
from yunohost.settings import settings_set
|
from yunohost.settings import settings_set
|
||||||
|
@ -13,6 +16,7 @@ from yunohost.utils.legacy import translate_legacy_settings_to_configpanel_setti
|
||||||
|
|
||||||
logger = getActionLogger("yunohost.migration")
|
logger = getActionLogger("yunohost.migration")
|
||||||
|
|
||||||
|
SETTINGS_PATH = "/etc/yunohost/settings.yml"
|
||||||
OLD_SETTINGS_PATH = "/etc/yunohost/settings.json"
|
OLD_SETTINGS_PATH = "/etc/yunohost/settings.json"
|
||||||
|
|
||||||
class MyMigration(Migration):
|
class MyMigration(Migration):
|
||||||
|
@ -26,7 +30,7 @@ class MyMigration(Migration):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
old_settings = json.load(open(OLD_SETTINGS_PATH))
|
old_settings = read_json(OLD_SETTINGS_PATH)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise YunohostError("global_settings_cant_open_settings", reason=e)
|
raise YunohostError("global_settings_cant_open_settings", reason=e)
|
||||||
|
|
||||||
|
@ -35,5 +39,6 @@ class MyMigration(Migration):
|
||||||
if settings.get('email.smtp.smtp_relay_host') != "":
|
if settings.get('email.smtp.smtp_relay_host') != "":
|
||||||
settings['email.smtp.smtp_relay_enabled'] = "True"
|
settings['email.smtp.smtp_relay_enabled'] = "True"
|
||||||
|
|
||||||
args = urllib.parse.urlencode(settings)
|
# Here we don't use settings_set() from settings.py to prevent
|
||||||
settings_set(args=args)
|
# Questions to be asked when one run the migration from CLI.
|
||||||
|
write_to_yaml(SETTINGS_PATH, settings)
|
||||||
|
|
|
@ -21,11 +21,9 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import yaml
|
||||||
from yunohost.settings import settings_get
|
|
||||||
|
|
||||||
SMALL_PWD_LIST = [
|
SMALL_PWD_LIST = [
|
||||||
"yunohost",
|
"yunohost",
|
||||||
|
@ -69,10 +67,9 @@ class PasswordValidator:
|
||||||
# from settings.py because this file is also meant to be
|
# from settings.py because this file is also meant to be
|
||||||
# use as a script by ssowat.
|
# use as a script by ssowat.
|
||||||
# (or at least that's my understanding -- Alex)
|
# (or at least that's my understanding -- Alex)
|
||||||
# Meh... I'll try to use settings_get() anyway... What could go
|
settings = yaml.load(open("/etc/yunohost/settings.yml", "r"))
|
||||||
# wrong ? And who even change password from SSOwat ? -- Tagada
|
|
||||||
setting_key = "security.password." + profile + "_strength"
|
setting_key = "security.password." + profile + "_strength"
|
||||||
self.validation_strength = settings_get(setting_key)
|
self.validation_strength = int(settings[setting_key])
|
||||||
except Exception:
|
except Exception:
|
||||||
# Fallback to default value if we can't fetch settings for some reason
|
# Fallback to default value if we can't fetch settings for some reason
|
||||||
self.validation_strength = 1
|
self.validation_strength = 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue