authn: Data migration for renaming 'container' to 'headers'.
Rename the 'auth_plugins' setting and all 'auth_container_%s' settings.
This commit is contained in:
parent
284957a394
commit
d1a5de5268
2 changed files with 81 additions and 1 deletions
|
|
@ -47,7 +47,7 @@ CONFIG = {}
|
|||
EXTENSIONS = {}
|
||||
|
||||
__version__ = ('.'.join((str(each) for each in VERSION[:3])))
|
||||
__dbversion__ = 51 # defines current db version for migrations
|
||||
__dbversion__ = 52 # defines current db version for migrations
|
||||
__platform__ = platform.system()
|
||||
__license__ = 'AGPLv3, and Commercial License'
|
||||
__author__ = 'RhodeCode GmbH'
|
||||
|
|
|
|||
80
rhodecode/lib/dbmigrate/versions/052_version_4_1_0.py
Normal file
80
rhodecode/lib/dbmigrate/versions/052_version_4_1_0.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from sqlalchemy.orm.attributes import flag_modified
|
||||
|
||||
from rhodecode.lib.dbmigrate.versions import _reset_base
|
||||
from rhodecode.model import init_model_encryption, meta
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
"""
|
||||
Upgrade operations go here.
|
||||
Don't create your own engine; bind migrate_engine to your metadata
|
||||
"""
|
||||
_reset_base(migrate_engine)
|
||||
from rhodecode.lib.dbmigrate.schema import db_3_7_0_0
|
||||
init_model_encryption(db_3_7_0_0)
|
||||
fixups(db_3_7_0_0, meta.Session)
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
pass
|
||||
|
||||
|
||||
AUTH_PLUGINS_SETTING = "auth_plugins"
|
||||
|
||||
PLUGIN_RENAME_MAP = {
|
||||
'egg:rhodecode-enterprise-ce#container': 'egg:rhodecode-enterprise-ce#headers',
|
||||
}
|
||||
|
||||
SETTINGS_RENAME_MAP = {
|
||||
'auth_container_cache_ttl': 'auth_headers_cache_ttl',
|
||||
'auth_container_clean_username': 'auth_headers_clean_username',
|
||||
'auth_container_enabled': 'auth_headers_enabled',
|
||||
'auth_container_fallback_header': 'auth_headers_fallback_header',
|
||||
'auth_container_header': 'auth_headers_header',
|
||||
}
|
||||
|
||||
|
||||
def rename_plugins(models, Session):
|
||||
query = models.RhodeCodeSetting.query().filter(
|
||||
models.RhodeCodeSetting.app_settings_name == AUTH_PLUGINS_SETTING)
|
||||
plugin_setting = query.scalar()
|
||||
plugins = plugin_setting.app_settings_value
|
||||
|
||||
new_plugins = []
|
||||
|
||||
for plugin_id in plugins:
|
||||
new_plugin_id = PLUGIN_RENAME_MAP.get(plugin_id, None)
|
||||
if new_plugin_id:
|
||||
new_plugins.append(new_plugin_id)
|
||||
else:
|
||||
new_plugins.append(plugin_id)
|
||||
|
||||
plugin_setting.app_settings_value = ','.join(new_plugins)
|
||||
|
||||
log.info("Rename of auth plugin IDs")
|
||||
log.info("Original setting value: %s", plugins)
|
||||
log.info("New setting value: %s", new_plugins)
|
||||
|
||||
|
||||
def rename_plugin_settings(models, Session):
|
||||
for old_name, new_name in SETTINGS_RENAME_MAP.items():
|
||||
query = models.RhodeCodeSetting.query().filter(
|
||||
models.RhodeCodeSetting.app_settings_name == old_name)
|
||||
setting = query.scalar()
|
||||
if setting:
|
||||
setting.app_settings_name = new_name
|
||||
log.info(
|
||||
'Rename of plugin setting "%s" to "%s"', old_name, new_name)
|
||||
|
||||
|
||||
def fixups(models, Session):
|
||||
rename_plugins(models, Session)
|
||||
rename_plugin_settings(models, Session)
|
||||
|
||||
Session().commit()
|
||||
Loading…
Add table
Add a link
Reference in a new issue