Skip to content

Commit

Permalink
Merge pull request #21 from chrismeyersfsu/AAP-35749-move-inject-cred…
Browse files Browse the repository at this point in the history
…ential-inv-update-id-condition

Do not inject extra var for inv update
  • Loading branch information
chrismeyersfsu authored Dec 18, 2024
2 parents 813749b + b07cfa6 commit d76326b
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 d76326b

Please sign in to comment.