mirror of
https://github.com/ansible/awx.git
synced 2026-03-09 05:29:26 -02:30
Add migration to prefill rh username and password for subscriptions
This commit is contained in:
committed by
Ryan Petrello
parent
e50c2c2867
commit
dd459e23e2
@@ -4,17 +4,23 @@ import logging
|
|||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
from awx.conf.migrations import _subscriptions as subscriptions
|
from awx.conf.migrations._subscriptions import clear_old_license, prefill_rh_credentials
|
||||||
|
|
||||||
logger = logging.getLogger('awx.conf.migrations')
|
logger = logging.getLogger('awx.conf.migrations')
|
||||||
|
|
||||||
|
|
||||||
|
def _noop(apps, schema_editor):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('conf', '0007_v380_rename_more_settings'),
|
('conf', '0007_v380_rename_more_settings'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RunPython(subscriptions.clear_old_license),
|
migrations.RunPython(clear_old_license, _noop),
|
||||||
|
migrations.RunPython(prefill_rh_credentials, _noop)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,11 +1,34 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import logging
|
import logging
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from awx.main.utils.encryption import decrypt_field, encrypt_field
|
||||||
|
|
||||||
logger = logging.getLogger('awx.conf.settings')
|
logger = logging.getLogger('awx.conf.settings')
|
||||||
|
|
||||||
__all__ = ['clear_old_license']
|
__all__ = ['clear_old_license', 'prefill_rh_credentials']
|
||||||
|
|
||||||
|
|
||||||
def clear_old_license(apps, schema_editor):
|
def clear_old_license(apps, schema_editor):
|
||||||
Setting = apps.get_model('conf', 'Setting')
|
Setting = apps.get_model('conf', 'Setting')
|
||||||
Setting.objects.filter(key='LICENSE').delete()
|
Setting.objects.filter(key='LICENSE').delete()
|
||||||
|
|
||||||
|
|
||||||
|
def _migrate_setting(apps, old_key, new_key, encrypted=False):
|
||||||
|
Setting = apps.get_model('conf', 'Setting')
|
||||||
|
if not Setting.objects.filter(key=old_key).exists():
|
||||||
|
return
|
||||||
|
new_setting = Setting.objects.create(key=new_key,
|
||||||
|
created=now(),
|
||||||
|
modified=now()
|
||||||
|
)
|
||||||
|
if encrypted:
|
||||||
|
new_setting.value = decrypt_field(Setting.objects.filter(key=old_key).first(), 'value')
|
||||||
|
new_setting.value = encrypt_field(new_setting, 'value')
|
||||||
|
else:
|
||||||
|
new_setting.value = getattr(Setting.objects.filter(key=old_key).first(), 'value')
|
||||||
|
new_setting.save()
|
||||||
|
|
||||||
|
|
||||||
|
def prefill_rh_credentials(apps, schema_editor):
|
||||||
|
_migrate_setting(apps, 'REDHAT_USERNAME', 'SUBSCRIPTIONS_USERNAME', encrypted=False)
|
||||||
|
_migrate_setting(apps, 'REDHAT_PASSWORD', 'SUBSCRIPTIONS_PASSWORD', encrypted=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user