From c62904ea02998fb2d0be1fdfe04e5906b4bcd5c4 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 22 Oct 2024 19:09:26 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20Discover=20injectors=20through?= =?UTF-8?q?=20entrypoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch eliminates import-based injector discovery, switching to distribution package-indepdendent hosting of the respective callables. --- awx/main/models/credential.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py index 052f5f9b6c4c..6049ecb53597 100644 --- a/awx/main/models/credential.py +++ b/awx/main/models/credential.py @@ -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 @@ -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 @@ -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: