Skip to content

Commit

Permalink
Address Lookup Plugins AttributeError (#15770)
Browse files Browse the repository at this point in the history
* fix backend attribute error

* managedcredential may now contain 2 different classes
* managedcredentialType and one that represents a lookup plugin

* conditionalize creation params

* added a conditional statement to filter our external types

* all external credentials are managed by awx/aap
  • Loading branch information
thedoubl3j authored Jan 29, 2025
1 parent d36cd6c commit c6930bd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions awx/main/models/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.namespace and instance.kind == "external":
native = ManagedCredentialType.registry[instance.namespace]
instance.inputs = native.inputs

return instance

def get_absolute_url(self, request=None):
Expand Down Expand Up @@ -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
Expand All @@ -555,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=True)
return dict(
namespace=cred_type.namespace,
kind=cred_type.kind,
Expand Down

0 comments on commit c6930bd

Please sign in to comment.