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 23, 2024
1 parent c7fc0a1 commit 5209559
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ thycotic_dsv = "awx_plugins.credentials.dsv:dsv_plugin"
thycotic_tss = "awx_plugins.credentials.tss:tss_plugin"
aws_secretsmanager_credential = "awx_plugins.credentials.aws_secretsmanager:aws_secretmanager_plugin"

[project.entry-points."awx_plugins.injector"]
aws = "awx_plugins.credential.injectors:aws"
azure_rm = "awx_plugins.credential.injectors:azure_rm"
ec2 = "awx_plugins.credential.injectors:aws"
gce = "awx_plugins.credential.injectors:gce"
kubernetes_bearer_token = "awx_plugins.credential.injectors:kubernetes_bearer_token"
openstack = "awx_plugins.credential.injectors:openstack"
terraform = "awx_plugins.credential.injectors:terraform"
vmware = "awx_plugins.credential.injectors:vmware"

[project.entry-points."awx_plugins.inventory"] # new entry points group name
azure-rm = "awx_plugins.inventory.plugins:azure_rm"
ec2 = "awx_plugins.inventory.plugins:ec2"
Expand Down
20 changes: 12 additions & 8 deletions src/awx_plugins/inventory/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from awx_plugins.interfaces._temporary_private_container_api import ( # noqa: WPS436
get_incontainer_path,
)
from awx_plugins.interfaces._temporary_private_injector_api import ( # noqa: WPS436
load_injector_callable,
)

import yaml

Expand Down Expand Up @@ -102,15 +105,16 @@ def _get_shared_env(
inventory_update.pk,
), # so injector knows this is inventory
}

if self.base_injector == 'managed':
from awx_plugins.credentials import injectors as builtin_injectors

cred_kind = inventory_update.source.replace('ec2', 'aws')
if cred_kind in dir(builtin_injectors):
getattr(
builtin_injectors,
cred_kind,
)(
try:
inject_credential_into_env = load_injector_callable(
inventory_update.source,
)
except LookupError:
pass # noqa: WPS420
else:
inject_credential_into_env(
credential,
injected_env,
private_data_dir,
Expand Down

0 comments on commit 5209559

Please sign in to comment.