mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
Merge pull request #2335 from rooftopcellist/patch_exp_setting
migrate AUTH_TOKEN_EXPIRATION to new session length setting
This commit is contained in:
26
awx/conf/migrations/0005_v330_rename_two_session_settings.py
Normal file
26
awx/conf/migrations/0005_v330_rename_two_session_settings.py
Normal file
@@ -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),
|
||||||
|
]
|
||||||
|
|
||||||
32
awx/conf/migrations/_rename_setting.py
Normal file
32
awx/conf/migrations/_rename_setting.py
Normal file
@@ -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()
|
||||||
|
)
|
||||||
|
|
||||||
@@ -71,6 +71,8 @@
|
|||||||
* Implemented OAuth2 support for token based authentication [[#21](https://github.com/ansible/awx/issues/21)].
|
* 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`.
|
* 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.
|
* 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
|
3.2.0
|
||||||
=====
|
=====
|
||||||
|
|||||||
Reference in New Issue
Block a user