mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
fix a few more migration-related issues for credentials
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@@ -95,4 +95,9 @@ class Migration(migrations.Migration):
|
|||||||
name='credentialtype',
|
name='credentialtype',
|
||||||
unique_together=set([('name', 'kind')]),
|
unique_together=set([('name', 'kind')]),
|
||||||
),
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='credential',
|
||||||
|
name='credential_type',
|
||||||
|
field=models.ForeignKey(related_name='credentials', to='main.CredentialType', null=False)
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import mock
|
from awx.main import utils
|
||||||
|
|
||||||
from awx.main.models import CredentialType
|
from awx.main.models import CredentialType
|
||||||
from awx.main.utils.common import encrypt_field, decrypt_field
|
from awx.main.utils.common import encrypt_field, decrypt_field
|
||||||
|
|
||||||
@@ -7,11 +6,12 @@ from awx.main.utils.common import encrypt_field, decrypt_field
|
|||||||
def migrate_to_v2_credentials(apps, schema_editor):
|
def migrate_to_v2_credentials(apps, schema_editor):
|
||||||
CredentialType.setup_tower_managed_defaults()
|
CredentialType.setup_tower_managed_defaults()
|
||||||
|
|
||||||
# this mock is necessary to make the implicit role generation save signal
|
# this monkey-patch is necessary to make the implicit role generation save
|
||||||
# use the correct Role model (the version active at this point in
|
# signal use the correct Role model (the version active at this point in
|
||||||
# migration, not the one at HEAD)
|
# migration, not the one at HEAD)
|
||||||
with mock.patch('awx.main.utils.get_current_apps', lambda: apps):
|
orig_current_apps = utils.get_current_apps
|
||||||
|
try:
|
||||||
|
utils.get_current_apps = lambda: apps
|
||||||
for cred in apps.get_model('main', 'Credential').objects.all():
|
for cred in apps.get_model('main', 'Credential').objects.all():
|
||||||
data = {}
|
data = {}
|
||||||
if getattr(cred, 'vault_password', None):
|
if getattr(cred, 'vault_password', None):
|
||||||
@@ -60,6 +60,8 @@ def migrate_to_v2_credentials(apps, schema_editor):
|
|||||||
setattr(new_cred, field, value)
|
setattr(new_cred, field, value)
|
||||||
new_cred.inputs[field] = encrypt_field(new_cred, field)
|
new_cred.inputs[field] = encrypt_field(new_cred, field)
|
||||||
setattr(new_cred, field, '')
|
setattr(new_cred, field, '')
|
||||||
else:
|
elif getattr(cred, field):
|
||||||
new_cred.inputs[field] = getattr(cred, field)
|
new_cred.inputs[field] = getattr(cred, field)
|
||||||
new_cred.save()
|
new_cred.save()
|
||||||
|
finally:
|
||||||
|
utils.get_current_apps = orig_current_apps
|
||||||
|
|||||||
@@ -234,6 +234,7 @@ class Credential(PasswordFieldsModel, CommonModelNameNotUnique, ResourceMixin):
|
|||||||
credential_type = models.ForeignKey(
|
credential_type = models.ForeignKey(
|
||||||
'CredentialType',
|
'CredentialType',
|
||||||
related_name='credentials',
|
related_name='credentials',
|
||||||
|
null=False,
|
||||||
help_text=_('Type for this credential. Credential Types define '
|
help_text=_('Type for this credential. Credential Types define '
|
||||||
'valid fields (e.g,. "username", "password") and their '
|
'valid fields (e.g,. "username", "password") and their '
|
||||||
'properties (e.g,. "username is required" or "password '
|
'properties (e.g,. "username is required" or "password '
|
||||||
|
|||||||
Reference in New Issue
Block a user