Skip to content

Commit

Permalink
Do not inject extra var for inv update
Browse files Browse the repository at this point in the history
* This logic was in AWX when inject_credential was originally moved
  over. I removed it because I couldn't trigger it in unit tests.
* I've since found out that it is needed due to a failing test in AWX
  and how the env would get set.
* This change includes a unit test to exercise and cover this path now.
  • Loading branch information
chrismeyersfsu committed Dec 18, 2024
1 parent 813749b commit b07cfa6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/awx_plugins/interfaces/_temporary_private_inject_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,18 @@ def inject_credential(
tmpl,
).render(**safe_namespace)

extra_vars = _build_extra_vars(
sandbox_env,
namespace,
cred_type.injectors.get(
'extra_vars', {},
),
)
if extra_vars:
path = _build_extra_vars_file(extra_vars, private_data_dir)
container_path = get_incontainer_path(path, private_data_dir)
args.extend(
# pylint: disable-next=consider-using-f-string
['-e', '@%s' % container_path],
if 'INVENTORY_UPDATE_ID' not in env:
extra_vars = _build_extra_vars(
sandbox_env,
namespace,
cred_type.injectors.get(
'extra_vars', {},
),
)
if extra_vars:
path = _build_extra_vars_file(extra_vars, private_data_dir)
container_path = get_incontainer_path(path, private_data_dir)
args.extend(
# pylint: disable-next=consider-using-f-string
['-e', '@%s' % container_path],
)
23 changes: 23 additions & 0 deletions tests/_temporary_private_inject_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,29 @@ def test_injectors_with_extra_vars(
assert expected_extra_vars.items() <= extra_vars.items()


def test_injectors_inv_update_id(private_data_dir: str) -> None:
"""Check that extra vars are not injected for an inventory update."""
cred_type = ManagedCredentialType(
namespace='animal',
name='dog',
kind='companion',
managed=True,
inputs={},
injectors={'extra_vars': {'do-not-inject': 'should-not-inject'}},
)
args: ArgsType = []
inject_credential(
cred_type,
Credential(inputs={}),
{'INVENTORY_UPDATE_ID': '1'},
{},
args,
private_data_dir,
)

assert not args


@pytest.mark.parametrize(
(
'inputs',
Expand Down

0 comments on commit b07cfa6

Please sign in to comment.