From a869d7da350e919baac1b005b48bae8e41f4ee74 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Thu, 6 Aug 2020 12:17:27 -0400 Subject: [PATCH] create the Galaxy credential for new installs in the preload script doing this in the migration *before* any Organizations actually exist is stirring up RBAC dragons that I don't have time to fight this commit meanst that *new* installs will pre-create the default Galaxy (public) credential in create_preload_data, while *upgraded/migrations* installs will do so via the migration --- awx/main/management/commands/create_preload_data.py | 10 ++++++++++ awx/main/migrations/_galaxy.py | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/awx/main/management/commands/create_preload_data.py b/awx/main/management/commands/create_preload_data.py index 297622af46..9b1d131735 100644 --- a/awx/main/management/commands/create_preload_data.py +++ b/awx/main/management/commands/create_preload_data.py @@ -42,6 +42,16 @@ class Command(BaseCommand): }, created_by=superuser) c.admin_role.members.add(superuser) + public_galaxy_credential = Credential( + name='Ansible Galaxy', + managed_by_tower=True, + credential_type=CredentialType.objects.get(kind='galaxy'), + inputs = { + 'url': 'https://galaxy.ansible.com/' + } + ) + public_galaxy_credential.save() + o.galaxy_credentials.add(public_galaxy_credential) i = Inventory.objects.create(name='Demo Inventory', organization=o, created_by=superuser) diff --git a/awx/main/migrations/_galaxy.py b/awx/main/migrations/_galaxy.py index 6341ee640c..b85b7b3aaf 100644 --- a/awx/main/migrations/_galaxy.py +++ b/awx/main/migrations/_galaxy.py @@ -14,9 +14,12 @@ logger = logging.getLogger('awx.main.migrations') def migrate_galaxy_settings(apps, schema_editor): + Organization = apps.get_model('main', 'Organization') + if Organization.objects.count() == 0: + # nothing to migrate + return set_current_apps(apps) ModernCredentialType.setup_tower_managed_defaults() - Organization = apps.get_model('main', 'Organization') CredentialType = apps.get_model('main', 'CredentialType') Credential = apps.get_model('main', 'Credential') Setting = apps.get_model('conf', 'Setting')