From 98401a4d7347516bdac4dbb9c7e0a1220fa9db65 Mon Sep 17 00:00:00 2001 From: thedoubl3j Date: Thu, 23 Jan 2025 16:17:04 -0500 Subject: [PATCH 1/3] fix backend attribute error * managedcredential may now contain 2 different classes * managedcredentialType and one that represents a lookup plugin --- awx/main/models/credential.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py index b9bacaae4c09..5908bf4f7a54 100644 --- a/awx/main/models/credential.py +++ b/awx/main/models/credential.py @@ -438,11 +438,15 @@ class Meta: @classmethod def from_db(cls, db, field_names, values): instance = super(CredentialType, cls).from_db(db, field_names, values) - if instance.managed and instance.namespace: + if instance.managed and instance.namespace and instance.kind != "external": native = ManagedCredentialType.registry[instance.namespace] instance.inputs = native.inputs instance.injectors = native.injectors instance.custom_injectors = getattr(native, 'custom_injectors', None) + elif instance.kind == "external": + native = ManagedCredentialType.registry[instance.namespace] + instance.inputs = native.inputs + return instance def get_absolute_url(self, request=None): @@ -544,7 +548,7 @@ def setup_tower_managed_defaults(cls, apps: Apps = None, app_config: AppConfig = @classmethod def load_plugin(cls, ns, plugin): # TODO: User "side-loaded" credential custom_injectors isn't supported - ManagedCredentialType.registry[ns] = ManagedCredentialType(namespace=ns, name=plugin.name, kind='external', inputs=plugin.inputs, injectors={}) + ManagedCredentialType.registry[ns] = SimpleNamespace(namespace=ns, name=plugin.name, kind='external', inputs=plugin.inputs, backend=plugin.backend) def inject_credential(self, credential, env, safe_env, args, private_data_dir): from awx_plugins.interfaces._temporary_private_inject_api import inject_credential From 411f8a344ca4398fbd42d44fd344da979910cda1 Mon Sep 17 00:00:00 2001 From: thedoubl3j Date: Tue, 28 Jan 2025 15:54:11 -0500 Subject: [PATCH 2/3] conditionalize creation params * added a conditional statement to filter our external types --- awx/main/models/credential.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py index 5908bf4f7a54..ec9ff4ec0f95 100644 --- a/awx/main/models/credential.py +++ b/awx/main/models/credential.py @@ -443,7 +443,7 @@ def from_db(cls, db, field_names, values): instance.inputs = native.inputs instance.injectors = native.injectors instance.custom_injectors = getattr(native, 'custom_injectors', None) - elif instance.kind == "external": + elif instance.namespace and instance.kind == "external": native = ManagedCredentialType.registry[instance.namespace] instance.inputs = native.inputs @@ -559,6 +559,8 @@ def inject_credential(self, credential, env, safe_env, args, private_data_dir): class CredentialTypeHelper: @classmethod def get_creation_params(cls, cred_type): + if cred_type.kind == 'external': + return dict(namespace=cred_type.namespace, kind=cred_type.kind, name=cred_type.name, managed=False) return dict( namespace=cred_type.namespace, kind=cred_type.kind, From 4adeb444294a23b158aa41d65250d2a27d7ec22b Mon Sep 17 00:00:00 2001 From: thedoubl3j Date: Tue, 28 Jan 2025 16:03:51 -0500 Subject: [PATCH 3/3] all external credentials are managed by awx/aap --- awx/main/models/credential.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py index ec9ff4ec0f95..df9283043c27 100644 --- a/awx/main/models/credential.py +++ b/awx/main/models/credential.py @@ -560,7 +560,7 @@ class CredentialTypeHelper: @classmethod def get_creation_params(cls, cred_type): if cred_type.kind == 'external': - return dict(namespace=cred_type.namespace, kind=cred_type.kind, name=cred_type.name, managed=False) + return dict(namespace=cred_type.namespace, kind=cred_type.kind, name=cred_type.name, managed=True) return dict( namespace=cred_type.namespace, kind=cred_type.kind,