Skip to content

Commit

Permalink
revert: BI-0 #774 (#778)
Browse files Browse the repository at this point in the history
Revert "fix: BI-5901 dict secrets deserializer fix (#774)"

This reverts commit 53279bc.
  • Loading branch information
juliarbkv authored Jan 10, 2025
1 parent 53279bc commit d9fd0b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/dl_core/dl_core/us_manager/us_entry_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collections import ChainMap
import copy
from functools import reduce
import json
import logging
from typing import (
ClassVar,
Expand Down Expand Up @@ -130,7 +131,8 @@ def deserialize(
for secret_key in declared_secret_keys:
if secret_source_addressable.contains(secret_key):
sec_val = secret_source_addressable.pop(secret_key)
raw_addressable.set(secret_key, sec_val)
sec_val_str = json.dumps(sec_val)
raw_addressable.set(secret_key, sec_val_str)

if secret_source_addressable.data:
LOGGER.warning("Undeclared secrets found")
Expand Down
11 changes: 8 additions & 3 deletions lib/dl_core/dl_core/us_manager/us_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from collections import ChainMap
from contextlib import contextmanager
import json
import logging
from typing import (
ClassVar,
Expand Down Expand Up @@ -341,9 +342,6 @@ def _entry_dict_to_obj(self, us_resp: dict, expected_type: Optional[Type[USEntry
secrets=us_resp.get("unversionedData"), # type: ignore # 2024-01-30 # TODO: Argument "secrets" to "USDataPack" has incompatible type "Any | None"; expected "dict[str, str | EncryptedData | None]" [arg-type]
)

for key, secret in data_pack.secrets.items():
data_pack.secrets[key] = self._crypto_controller.decrypt(secret) # type: ignore # TODO: Argument 1 to "decrypt" of "CryptoController" has incompatible type "str | EncryptedData | None"; expected "EncryptedData | None" [arg-type]

entry = serializer.deserialize(
entry_cls,
data_pack,
Expand All @@ -352,6 +350,11 @@ def _entry_dict_to_obj(self, us_resp: dict, expected_type: Optional[Type[USEntry
common_properties=common_properties,
data_strict=False,
)
secret_keys = serializer.get_secret_keys(entry_cls)
for key in secret_keys:
old_data = serializer.get_data_attr(entry, key)
decrypted_data = self._crypto_controller.decrypt(json.loads(old_data)) if old_data is not None else None
serializer.set_data_attr(entry, key, decrypted_data)

entry.stored_in_db = True
entry._us_resp = us_resp
Expand Down Expand Up @@ -430,6 +433,8 @@ def _get_entry_save_params(self, entry: USEntry) -> dict:
data_pack = USDataPack(data=data_dict)

for key, secret in data_pack.secrets.items():
if isinstance(secret, dict):
secret = json.dumps(secret)
assert secret is None or isinstance(secret, str)
data_pack.secrets[key] = self._crypto_controller.encrypt_with_actual_key(secret)

Expand Down

0 comments on commit d9fd0b1

Please sign in to comment.