Skip to content

Commit 121eb92

Browse files
committed
Fix to save encrypted string in credentials
1 parent 5a058be commit 121eb92

File tree

3 files changed

+277
-26
lines changed

3 files changed

+277
-26
lines changed

src/aap_eda/api/views/eda_credential.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
from aap_eda.api import exceptions, filters, serializers
3232
from aap_eda.api.serializers.eda_credential import get_references
3333
from aap_eda.core import models
34-
from aap_eda.core.utils.credentials import inputs_to_store
34+
from aap_eda.core.utils.credentials import (
35+
inputs_to_store,
36+
inputs_to_store_dict,
37+
)
3538
from aap_eda.utils import str_to_bool
3639

3740
from .mixins import (
@@ -193,8 +196,14 @@ def list(self, request):
193196
)
194197
def partial_update(self, request, pk):
195198
eda_credential = self.get_object()
199+
data = request.data
200+
201+
data["inputs"] = inputs_to_store_dict(
202+
data.get("inputs", {}), eda_credential.inputs
203+
)
204+
196205
serializer = serializers.EdaCredentialCreateSerializer(
197-
eda_credential, data=request.data, partial=True
206+
eda_credential, data=data, partial=True
198207
)
199208
serializer.is_valid(raise_exception=True)
200209

src/aap_eda/core/utils/credentials.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def get_secret_fields(schema: dict) -> list[str]:
6060

6161

6262
def inputs_to_store(inputs: dict, old_inputs_str: str = None) -> str:
63+
return yaml.dump(inputs_to_store_dict(inputs, old_inputs_str))
64+
65+
66+
def inputs_to_store_dict(inputs: dict, old_inputs_str: str = None) -> dict:
6367
old_inputs = (
6468
inputs_from_store(old_inputs_str.get_secret_value())
6569
if old_inputs_str
@@ -69,7 +73,7 @@ def inputs_to_store(inputs: dict, old_inputs_str: str = None) -> str:
6973
old_inputs.update(
7074
(k, inputs[k]) for k, v in inputs.items() if v != ENCRYPTED_STRING
7175
)
72-
return yaml.dump(old_inputs, sort_keys=False)
76+
return old_inputs
7377

7478

7579
def inputs_from_store(inputs: str) -> dict:

0 commit comments

Comments
 (0)