Skip to content
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

revert: BI-0 https://github.com/datalens-tech/datalens-backend/pull/774 #778

Merged
merged 1 commit into from
Jan 10, 2025
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
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
Loading