Skip to content

Commit e91d392

Browse files
authored
fix: [AAP-47135] Only return user-input extra_var to the UI (#1340)
Remove the extra_var from credential types, and only return user-input ones. Before: ![image](https://github.com/user-attachments/assets/e42a2f41-c852-4559-a36a-41dd82c0f515) After: ![image](https://github.com/user-attachments/assets/3c93ee3a-17b5-41db-a47d-fe6289185eb4) https://issues.redhat.com/browse/AAP-47135
1 parent 2db001e commit e91d392

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

src/aap_eda/api/serializers/activation.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ def to_representation(self, activation):
378378
for credential in activation.eda_credentials.filter(managed=False)
379379
]
380380
extra_var = (
381-
replace_vault_data(activation.extra_var)
381+
replace_vault_data(
382+
_get_user_extra_vars(activation, activation.extra_var)
383+
)
382384
if activation.extra_var
383385
else None
384386
)
@@ -761,7 +763,9 @@ def update(
761763

762764
def to_representation(self, activation):
763765
extra_var = (
764-
replace_vault_data(activation.extra_var)
766+
replace_vault_data(
767+
_get_user_extra_vars(activation, activation.extra_var)
768+
)
765769
if activation.extra_var
766770
else None
767771
)
@@ -956,7 +960,9 @@ def to_representation(self, activation):
956960
for credential in activation.eda_credentials.filter(managed=False)
957961
]
958962
extra_var = (
959-
replace_vault_data(activation.extra_var)
963+
replace_vault_data(
964+
_get_user_extra_vars(activation, activation.extra_var)
965+
)
960966
if activation.extra_var
961967
else None
962968
)

tests/integration/api/test_activation_with_credential.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,9 @@ def test_create_activation_without_extra_vars_single_credential(
464464
assert response.status_code == status.HTTP_201_CREATED
465465
assert response.data["extra_var"]
466466
extra_var = yaml.safe_load(response.data["extra_var"])
467-
assert extra_var["sasl_username"] == "adam"
468-
assert extra_var["sasl_password"] == "secret"
467+
# Check that the extra_var not contains the credential inputs
468+
assert extra_var.get("sasl_username") is None
469+
assert extra_var.get("sasl_password") is None
469470

470471

471472
@pytest.mark.django_db
@@ -550,8 +551,8 @@ def test_create_activation_with_extra_vars_user_credential(
550551
assert response.data["extra_var"]
551552
original_extra_var = yaml.safe_load(EXTRA_VAR)
552553
extra_var = yaml.safe_load(response.data["extra_var"])
553-
assert extra_var["sasl_username"] == "adam"
554-
assert extra_var["sasl_password"] == "secret"
554+
assert extra_var.get("sasl_username") is None
555+
assert extra_var.get("sasl_password") is None
555556
for key, value in original_extra_var.items():
556557
assert value == extra_var[key]
557558

@@ -638,10 +639,10 @@ def test_create_activation_with_extra_vars_mix_credential(
638639
assert response.data["extra_var"]
639640
original_extra_var = yaml.safe_load(EXTRA_VAR)
640641
extra_var = yaml.safe_load(response.data["extra_var"])
641-
assert extra_var["sasl_username"] == "adam"
642-
assert extra_var["sasl_password"] == "secret"
643-
assert extra_var["custom_username"] == "fred"
644-
assert extra_var["custom_password"] == "password"
642+
assert extra_var.get("sasl_username") is None
643+
assert extra_var.get("sasl_password") is None
644+
assert extra_var.get("custom_username") is None
645+
assert extra_var.get("custom_password") is None
645646
for key, value in original_extra_var.items():
646647
assert value == extra_var[key]
647648

@@ -972,10 +973,7 @@ def test_update_activation_credentials(
972973
f"{api_url_v1}/activations/", data=test_activation
973974
)
974975
assert response.data["eda_credentials"][0]["id"] == eda_credential1["id"]
975-
assert (
976-
response.data["extra_var"]
977-
== "MY_VAR1: foo\nMY_VAR2: 100\nUSER_VAR: custom\n"
978-
)
976+
assert response.data["extra_var"] == "USER_VAR: custom\n"
979977

980978
credential_type2_inputs = {
981979
"fields": [
@@ -1005,7 +1003,7 @@ def test_update_activation_credentials(
10051003
data={"eda_credentials": [eda_credential2["id"]]},
10061004
)
10071005
assert response.data["eda_credentials"][0]["id"] == eda_credential2["id"]
1008-
assert response.data["extra_var"] == "MY_VAR3: foo3\nUSER_VAR: custom\n"
1006+
assert response.data["extra_var"] == "USER_VAR: custom\n"
10091007

10101008
response = admin_client.patch(
10111009
f"{api_url_v1}/activations/{response.data['id']}/",
@@ -1014,7 +1012,7 @@ def test_update_activation_credentials(
10141012
"extra_var": "MY_VAR3: foo3\nUSER_VAR: custom\n",
10151013
},
10161014
)
1017-
assert response.data["extra_var"] == "MY_VAR3: foo3\nUSER_VAR: custom\n"
1015+
assert response.data["extra_var"] == "USER_VAR: custom\n"
10181016

10191017
response = admin_client.patch(
10201018
f"{api_url_v1}/activations/{response.data['id']}/",

tests/integration/api/test_activation_with_event_stream.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,7 @@ def test_update_activation_with_everything(
881881
assert_updated_event_stream_mapping(
882882
response, ["ansible.eda.range"], "[]", ""
883883
)
884-
assert response.data["extra_var"] != extra_var
885-
assert response.data["extra_var"] in extra_var
884+
assert response.data["extra_var"] == extra_var
886885

887886

888887
@pytest.mark.django_db

0 commit comments

Comments
 (0)