Skip to content

fix: (AAP-29642) - Fix to save encrypted string in credentials #1021

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

Merged
merged 1 commit into from
Aug 26, 2024
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: 11 additions & 2 deletions src/aap_eda/api/views/eda_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
from aap_eda.api import exceptions, filters, serializers
from aap_eda.api.serializers.eda_credential import get_references
from aap_eda.core import models
from aap_eda.core.utils.credentials import inputs_to_store
from aap_eda.core.utils.credentials import (
inputs_to_store,
inputs_to_store_dict,
)
from aap_eda.utils import str_to_bool

from .mixins import (
Expand Down Expand Up @@ -193,8 +196,14 @@ def list(self, request):
)
def partial_update(self, request, pk):
eda_credential = self.get_object()
data = request.data

data["inputs"] = inputs_to_store_dict(
data.get("inputs", {}), eda_credential.inputs
)

serializer = serializers.EdaCredentialCreateSerializer(
eda_credential, data=request.data, partial=True
eda_credential, data=data, partial=True
)
serializer.is_valid(raise_exception=True)

Expand Down
6 changes: 5 additions & 1 deletion src/aap_eda/core/utils/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def get_secret_fields(schema: dict) -> list[str]:


def inputs_to_store(inputs: dict, old_inputs_str: str = None) -> str:
return yaml.dump(inputs_to_store_dict(inputs, old_inputs_str))


def inputs_to_store_dict(inputs: dict, old_inputs_str: str = None) -> dict:
old_inputs = (
inputs_from_store(old_inputs_str.get_secret_value())
if old_inputs_str
Expand All @@ -69,7 +73,7 @@ def inputs_to_store(inputs: dict, old_inputs_str: str = None) -> str:
old_inputs.update(
(k, inputs[k]) for k, v in inputs.items() if v != ENCRYPTED_STRING
)
return yaml.dump(old_inputs, sort_keys=False)
return old_inputs


def inputs_from_store(inputs: str) -> dict:
Expand Down
Loading
Loading