feature: moves token generation to config_maker.py file
This commit is contained in:
parent
3683a35b08
commit
46c6576e08
4 changed files with 27 additions and 27 deletions
|
|
@ -24,11 +24,34 @@ from pyramid.settings import asbool
|
|||
|
||||
from rhodecode.config.settings_maker import SettingsMaker
|
||||
from rhodecode.config import utils as config_utils
|
||||
from rhodecode.lib.config_utils import initialize_ini_config_default_values_if_not_present
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def initialize_ini_config_default_values_if_not_present(ini_path: str):
|
||||
from configupdater import ConfigUpdater # use configupdater to not break comments and formatting's
|
||||
|
||||
def dump_config():
|
||||
with open(ini_path, "w") as configfile:
|
||||
updater.write(configfile)
|
||||
|
||||
updater = ConfigUpdater()
|
||||
updater.read(ini_path)
|
||||
|
||||
section = "app:main"
|
||||
option = "app.service_api.token"
|
||||
|
||||
if not updater[section][option].value.strip():
|
||||
updater[section][option] = generate_token()
|
||||
dump_config()
|
||||
|
||||
|
||||
def generate_token(length: int = 32) -> str:
|
||||
import secrets
|
||||
|
||||
return secrets.token_urlsafe(length)
|
||||
|
||||
|
||||
def sanitize_settings_and_apply_defaults(global_config, settings):
|
||||
"""
|
||||
Applies settings defaults and does all type conversion.
|
||||
|
|
|
|||
|
|
@ -40,27 +40,3 @@ def get_app_config(ini_path):
|
|||
from paste.deploy.loadwsgi import appconfig
|
||||
|
||||
return appconfig(f"config:{ini_path}", relative_to=os.getcwd())
|
||||
|
||||
|
||||
def initialize_ini_config_default_values_if_not_present(ini_path: str):
|
||||
from configupdater import ConfigUpdater # use configupdater to not break comments and formatting's
|
||||
|
||||
def dump_config():
|
||||
with open(ini_path, "w") as configfile:
|
||||
updater.write(configfile)
|
||||
|
||||
updater = ConfigUpdater()
|
||||
updater.read(ini_path)
|
||||
|
||||
section = "app:main"
|
||||
option = "app.service_api.token"
|
||||
|
||||
if not updater[section][option].value.strip():
|
||||
updater[section][option] = generate_token()
|
||||
dump_config()
|
||||
|
||||
|
||||
def generate_token(length: int = 32) -> str:
|
||||
import secrets
|
||||
|
||||
return secrets.token_urlsafe(length)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
import time
|
||||
import logging
|
||||
|
||||
from rhodecode.lib.config_utils import get_app_config_lightweight, initialize_ini_config_default_values_if_not_present
|
||||
from rhodecode.config.config_maker import initialize_ini_config_default_values_if_not_present
|
||||
from rhodecode.lib.config_utils import get_app_config_lightweight
|
||||
|
||||
from rhodecode.lib.hook_daemon.base import Hooks
|
||||
from rhodecode.lib.hook_daemon.hook_module import HooksModuleCallbackDaemon
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import os
|
|||
from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # pragma: no cover
|
||||
from pyramid.threadlocal import get_current_request as pyramid_current_request
|
||||
|
||||
from rhodecode.lib.config_utils import initialize_ini_config_default_values_if_not_present
|
||||
from rhodecode.config.config_maker import initialize_ini_config_default_values_if_not_present
|
||||
|
||||
|
||||
def bootstrap(config_uri, options=None, env=None):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue