diff --git a/awx/conf/migrations/0005_v330_rename_two_session_settings.py b/awx/conf/migrations/0005_v330_rename_two_session_settings.py new file mode 100644 index 0000000000..4e4b561ec4 --- /dev/null +++ b/awx/conf/migrations/0005_v330_rename_two_session_settings.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals +from django.db import migrations +from awx.conf.migrations import _rename_setting + + +def copy_session_settings(apps, schema_editor): + _rename_setting.rename_setting(apps, schema_editor, old_key='AUTH_TOKEN_PER_USER', new_key='SESSIONS_PER_USER') + _rename_setting.rename_setting(apps, schema_editor, old_key='AUTH_TOKEN_EXPIRATION', new_key='SESSION_COOKIE_AGE') + + +def reverse_copy_session_settings(apps, schema_editor): + _rename_setting.rename_setting(apps, schema_editor, old_key='SESSION_COOKIE_AGE', new_key='AUTH_TOKEN_EXPIRATION') + _rename_setting.rename_setting(apps, schema_editor, old_key='SESSIONS_PER_USER', new_key='AUTH_TOKEN_PER_USER') + + +class Migration(migrations.Migration): + + dependencies = [ + ('conf', '0004_v320_reencrypt'), + ] + + operations = [ + migrations.RunPython(copy_session_settings, reverse_copy_session_settings), + ] + \ No newline at end of file diff --git a/awx/conf/migrations/_rename_setting.py b/awx/conf/migrations/_rename_setting.py new file mode 100644 index 0000000000..dbbc347edf --- /dev/null +++ b/awx/conf/migrations/_rename_setting.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals +import logging +from django.utils.timezone import now +from django.conf import settings + +logger = logging.getLogger('awx.conf.settings') + +__all__ = ['rename_setting'] + + +def rename_setting(apps, schema_editor, old_key, new_key): + + old_setting = None + Setting = apps.get_model('conf', 'Setting') + if Setting.objects.filter(key=new_key).exists() or hasattr(settings, new_key): + logger.info('Setting ' + new_key + ' unexpectedly exists before this migration, it will be replaced by the value of the ' + old_key + ' setting.') + Setting.objects.filter(key=new_key).delete() + # Look for db setting, which wouldn't be picked up by SettingsWrapper because the register method is gone + if Setting.objects.filter(key=old_key).exists(): + old_setting = Setting.objects.filter(key=old_key).last().value + Setting.objects.filter(key=old_key).delete() + # Look for "on-disk" setting (/etc/tower/conf.d) + if hasattr(settings, old_key): + old_setting = getattr(settings, old_key) + if old_setting is not None: + Setting.objects.create(key=new_key, + value=old_setting, + created=now(), + modified=now() + ) + diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 96cd3b7bc4..db33422427 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -71,6 +71,8 @@ * Implemented OAuth2 support for token based authentication [[#21](https://github.com/ansible/awx/issues/21)]. * Added the ability to forcibly expire sessions through `awx-manage expire_sessions`. * Disallowed using HTTP PUT/PATCH methods to modify existing jobs in Job Details API endpoint. +* Changed the name of the session length setting from `AUTH_TOKEN_EXPIRATION` to `SESSION_COOKIE_AGE`. +* Changed the name of the session length setting from `AUTH_TOKEN_PER_USER` to `SESSIONS_PER_USER`. 3.2.0 =====