Skip to content

Commit

Permalink
📦 Discover injectors through entrypoints
Browse files Browse the repository at this point in the history
This patch eliminates import-based injector discovery, switching to
distribution package-indepdendent hosting of the respective callables.
  • Loading branch information
webknjaz committed Oct 22, 2024
1 parent 764dcbf commit c62904e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions awx/main/models/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

# Shared code for the AWX platform
from awx_plugins.interfaces._temporary_private_container_api import get_incontainer_path
from awx_plugins.interfaces._temporary_private_injector_api import load_injector_callable

# DRF
from awx.main.utils.pglock import advisory_lock
Expand All @@ -53,7 +54,6 @@
)
from awx.main.models import Team, Organization
from awx.main.utils import encrypt_field
from awx_plugins.credentials import injectors as builtin_injectors

# DAB
from ansible_base.resource_registry.tasks.sync import get_resource_server_client
Expand Down Expand Up @@ -566,11 +566,22 @@ def inject_credential(self, credential, env, safe_env, args, private_data_dir):
files)
"""
if not self.injectors:
if self.managed and credential.credential_type.namespace in dir(builtin_injectors):
injected_env = {}
getattr(builtin_injectors, credential.credential_type.namespace)(credential, injected_env, private_data_dir)
env.update(injected_env)
safe_env.update(build_safe_env(injected_env))
if self.managed:
try:
inject_credential_into_env = load_injector_callable(
credential.credential_type.namespace,
)
except LookupError:
pass
else:
injected_env = {}
inject_credential_into_env(
credential,
injected_env,
private_data_dir,
)
env.update(injected_env)
safe_env.update(build_safe_env(injected_env))
return

class TowerNamespace:
Expand Down

0 comments on commit c62904e

Please sign in to comment.