From d9fd0b127d480f06a60fbaf840085fa9c3910658 Mon Sep 17 00:00:00 2001 From: Julia R Date: Fri, 10 Jan 2025 19:07:52 +0300 Subject: [PATCH] revert: BI-0 https://github.com/datalens-tech/datalens-backend/pull/774 (#778) Revert "fix: BI-5901 dict secrets deserializer fix (#774)" This reverts commit 53279bc17ef38ddb4896443a09604e2771b81e1e. --- lib/dl_core/dl_core/us_manager/us_entry_serializer.py | 4 +++- lib/dl_core/dl_core/us_manager/us_manager.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/dl_core/dl_core/us_manager/us_entry_serializer.py b/lib/dl_core/dl_core/us_manager/us_entry_serializer.py index 1ed01cbf4..87a37823c 100644 --- a/lib/dl_core/dl_core/us_manager/us_entry_serializer.py +++ b/lib/dl_core/dl_core/us_manager/us_entry_serializer.py @@ -4,6 +4,7 @@ from collections import ChainMap import copy from functools import reduce +import json import logging from typing import ( ClassVar, @@ -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") diff --git a/lib/dl_core/dl_core/us_manager/us_manager.py b/lib/dl_core/dl_core/us_manager/us_manager.py index 0b91f0abb..e0a508534 100644 --- a/lib/dl_core/dl_core/us_manager/us_manager.py +++ b/lib/dl_core/dl_core/us_manager/us_manager.py @@ -2,6 +2,7 @@ from collections import ChainMap from contextlib import contextmanager +import json import logging from typing import ( ClassVar, @@ -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, @@ -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 @@ -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)