mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 02:50:02 -03:30
Pass current apps to CredentialType setup method
This commit is contained in:
parent
06b04007a0
commit
cc616206b3
@ -10,7 +10,7 @@ from awx.main.utils.common import set_current_apps
|
||||
|
||||
def migrate_to_static_inputs(apps, schema_editor):
|
||||
set_current_apps(apps)
|
||||
CredentialType.setup_tower_managed_defaults()
|
||||
CredentialType.setup_tower_managed_defaults(apps)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@ -14,7 +14,7 @@ from awx.main.utils.common import set_current_apps
|
||||
|
||||
def setup_tower_managed_defaults(apps, schema_editor):
|
||||
set_current_apps(apps)
|
||||
CredentialType.setup_tower_managed_defaults()
|
||||
CredentialType.setup_tower_managed_defaults(apps)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@ -8,7 +8,7 @@ from awx.main.utils.common import set_current_apps
|
||||
|
||||
def setup_tower_managed_defaults(apps, schema_editor):
|
||||
set_current_apps(apps)
|
||||
CredentialType.setup_tower_managed_defaults()
|
||||
CredentialType.setup_tower_managed_defaults(apps)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@ -9,7 +9,7 @@ from awx.main.utils.common import set_current_apps
|
||||
|
||||
def create_new_credential_types(apps, schema_editor):
|
||||
set_current_apps(apps)
|
||||
CredentialType.setup_tower_managed_defaults()
|
||||
CredentialType.setup_tower_managed_defaults(apps)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@ -5,7 +5,7 @@ from awx.main.models import CredentialType
|
||||
|
||||
|
||||
def update_cyberark_aim_name(apps, schema_editor):
|
||||
CredentialType.setup_tower_managed_defaults()
|
||||
CredentialType.setup_tower_managed_defaults(apps)
|
||||
aim_types = apps.get_model('main', 'CredentialType').objects.filter(namespace='aim').order_by('id')
|
||||
|
||||
if aim_types.count() == 2:
|
||||
|
||||
@ -6,7 +6,7 @@ from awx.main.utils.common import set_current_apps
|
||||
|
||||
def setup_tower_managed_defaults(apps, schema_editor):
|
||||
set_current_apps(apps)
|
||||
CredentialType.setup_tower_managed_defaults()
|
||||
CredentialType.setup_tower_managed_defaults(apps)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@ -32,7 +32,7 @@ def forwards(apps, schema_editor):
|
||||
tower_type.namespace = 'controller' # if not done, will error setup_tower_managed_defaults
|
||||
tower_type.save(update_fields=['name', 'namespace'])
|
||||
|
||||
ModernCredentialType.setup_tower_managed_defaults()
|
||||
ModernCredentialType.setup_tower_managed_defaults(apps)
|
||||
|
||||
|
||||
def backwards(apps, schema_editor):
|
||||
|
||||
@ -19,7 +19,7 @@ def migrate_galaxy_settings(apps, schema_editor):
|
||||
# nothing to migrate
|
||||
return
|
||||
set_current_apps(apps)
|
||||
ModernCredentialType.setup_tower_managed_defaults()
|
||||
ModernCredentialType.setup_tower_managed_defaults(apps)
|
||||
CredentialType = apps.get_model('main', 'CredentialType')
|
||||
Credential = apps.get_model('main', 'Credential')
|
||||
Setting = apps.get_model('conf', 'Setting')
|
||||
@ -37,10 +37,15 @@ def migrate_galaxy_settings(apps, schema_editor):
|
||||
try:
|
||||
# Needed for old migrations
|
||||
public_galaxy_credential = Credential(
|
||||
created=now(), modified=now(), name='Ansible Galaxy', managed_by_tower=True, credential_type=galaxy_type, inputs={'url': 'https://galaxy.ansible.com/'}
|
||||
created=now(),
|
||||
modified=now(),
|
||||
name='Ansible Galaxy',
|
||||
managed_by_tower=True,
|
||||
credential_type=galaxy_type,
|
||||
inputs={'url': 'https://galaxy.ansible.com/'},
|
||||
)
|
||||
except:
|
||||
# This will make functionaly tests pass
|
||||
# Needed for new migrations, tests
|
||||
public_galaxy_credential = Credential(
|
||||
created=now(), modified=now(), name='Ansible Galaxy', managed=True, credential_type=galaxy_type, inputs={'url': 'https://galaxy.ansible.com/'}
|
||||
)
|
||||
|
||||
@ -19,6 +19,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext_noop
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.timezone import now
|
||||
|
||||
# AWX
|
||||
from awx.api.versioning import reverse
|
||||
@ -395,9 +396,13 @@ class CredentialType(CommonModelNameNotUnique):
|
||||
return dict((k, functools.partial(v.create)) for k, v in ManagedCredentialType.registry.items())
|
||||
|
||||
@classmethod
|
||||
def setup_tower_managed_defaults(cls):
|
||||
def setup_tower_managed_defaults(cls, apps=None):
|
||||
if apps is not None:
|
||||
ct_class = apps.get_model('main', 'CredentialType')
|
||||
else:
|
||||
ct_class = CredentialType
|
||||
for default in ManagedCredentialType.registry.values():
|
||||
existing = CredentialType.objects.filter(name=default.name, kind=default.kind).first()
|
||||
existing = ct_class.objects.filter(name=default.name, kind=default.kind).first()
|
||||
if existing is not None:
|
||||
existing.namespace = default.namespace
|
||||
existing.inputs = {}
|
||||
@ -405,7 +410,11 @@ class CredentialType(CommonModelNameNotUnique):
|
||||
existing.save()
|
||||
continue
|
||||
logger.debug(_("adding %s credential type" % default.name))
|
||||
created = default.create()
|
||||
params = default.get_creation_params()
|
||||
if 'managed' not in [f.name for f in ct_class._meta.get_fields()]:
|
||||
params['managed_by_tower'] = params.pop('managed')
|
||||
params['created'] = params['modified'] = now() # CreatedModifiedModel service
|
||||
created = ct_class(**params)
|
||||
created.inputs = created.injectors = {}
|
||||
created.save()
|
||||
|
||||
@ -556,8 +565,8 @@ class ManagedCredentialType(SimpleNamespace):
|
||||
)
|
||||
ManagedCredentialType.registry[namespace] = self
|
||||
|
||||
def create(self):
|
||||
return CredentialType(
|
||||
def get_creation_params(self):
|
||||
return dict(
|
||||
namespace=self.namespace,
|
||||
kind=self.kind,
|
||||
name=self.name,
|
||||
@ -566,6 +575,9 @@ class ManagedCredentialType(SimpleNamespace):
|
||||
injectors=self.injectors,
|
||||
)
|
||||
|
||||
def create(self):
|
||||
return CredentialType(**self.get_creation_params())
|
||||
|
||||
|
||||
ManagedCredentialType(
|
||||
namespace='ssh',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user