Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt custom_injectors change from awx-plugins #15638

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions awx/main/models/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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 @@ -438,6 +437,7 @@
default=dict,
help_text=_('Enter injectors using either JSON or YAML syntax. Refer to the documentation for example syntax.'),
)
custom_injectors = None

@classmethod
def from_db(cls, db, field_names, values):
Expand All @@ -446,6 +446,7 @@
native = ManagedCredentialType.registry[instance.namespace]
instance.inputs = native.inputs
instance.injectors = native.injectors
instance.custom_injectors = native.custom_injectors
return instance

def get_absolute_url(self, request=None):
Expand Down Expand Up @@ -547,6 +548,7 @@

@classmethod
def load_plugin(cls, ns, plugin):
# TODO: User "side-loaded" credential custom_injectors isn't supported
ManagedCredentialType(namespace=ns, name=plugin.name, kind='external', inputs=plugin.inputs)

def inject_credential(self, credential, env, safe_env, args, private_data_dir):
Expand Down Expand Up @@ -575,9 +577,9 @@
files)
"""
if not self.injectors:
if self.managed and credential.credential_type.namespace in dir(builtin_injectors):
if self.managed and credential.credential_type.custom_injectors:
injected_env = {}
getattr(builtin_injectors, credential.credential_type.namespace)(credential, injected_env, private_data_dir)
credential.credential_type.custom_injectors(credential, injected_env, private_data_dir)

Check warning on line 582 in awx/main/models/credential.py

View check run for this annotation

Codecov / codecov/patch

awx/main/models/credential.py#L582

Added line #L582 was not covered by tests
env.update(injected_env)
safe_env.update(build_safe_env(injected_env))
return
Expand Down Expand Up @@ -686,6 +688,7 @@
for k in ('inputs', 'injectors'):
if k not in kwargs:
kwargs[k] = {}
kwargs.setdefault('custom_injectors', None)
super(ManagedCredentialType, self).__init__(namespace=namespace, **kwargs)
if namespace in ManagedCredentialType.registry:
raise ValueError(
Expand All @@ -706,7 +709,9 @@
)

def create(self):
return CredentialType(**self.get_creation_params())
res = CredentialType(**self.get_creation_params())
res.custom_injectors = self.custom_injectors
return res


class CredentialInputSource(PrimordialModel):
Expand Down
3 changes: 2 additions & 1 deletion awx/main/tests/functional/test_inventory_source_injectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ def create_reference_data(source_dir, env, content):
json.dump(env, f, indent=4, sort_keys=True)


@mock.patch('awx_plugins.interfaces._temporary_private_licensing_api.detect_server_product_name', return_value='NOT-AWX')
@pytest.mark.django_db
@pytest.mark.parametrize('this_kind', discover_available_cloud_provider_plugin_names())
def test_inventory_update_injected_content(this_kind, inventory, fake_credential_factory, mock_me):
def test_inventory_update_injected_content(product_name, this_kind, inventory, fake_credential_factory, mock_me):
if this_kind.endswith('_supported'):
this_kind = this_kind[:-10]

Expand Down
Loading