From fc333aaa794e787ae493834d652eeef1a9a49186 Mon Sep 17 00:00:00 2001 From: virgilwong Date: Sat, 13 Dec 2025 10:04:37 +0800 Subject: [PATCH] Fix: fix CI failure.(#11837) --- common/crypto_utils.py | 20 ++++++++------------ rag/utils/encrypted_storage.py | 9 ++++----- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/common/crypto_utils.py b/common/crypto_utils.py index 2f03da4c5..5dcbd2937 100644 --- a/common/crypto_utils.py +++ b/common/crypto_utils.py @@ -15,13 +15,11 @@ # import os -import logging from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives import padding from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC from cryptography.hazmat.primitives import hashes -import base64 class BaseCrypto: @@ -294,13 +292,12 @@ class CryptoUtil: Returns: Encrypted data (bytes) """ - import time - start_time = time.time() + # import time + # start_time = time.time() encrypted = self.crypto.encrypt(data) - end_time = time.time() + # end_time = time.time() # logging.info(f"Encryption completed, data length: {len(data)} bytes, time: {(end_time - start_time)*1000:.2f} ms") return encrypted - # return self.crypto.encrypt(data) def decrypt(self, encrypted_data): """ @@ -312,13 +309,12 @@ class CryptoUtil: Returns: Decrypted data (bytes) """ - import time - start_time = time.time() + # import time + # start_time = time.time() decrypted = self.crypto.decrypt(encrypted_data) - end_time = time.time() + # end_time = time.time() # logging.info(f"Decryption completed, data length: {len(encrypted_data)} bytes, time: {(end_time - start_time)*1000:.2f} ms") return decrypted - # return self.crypto.decrypt(encrypted_data) # Test code @@ -330,7 +326,7 @@ if __name__ == "__main__": encrypted = crypto.encrypt(test_data) decrypted = crypto.decrypt(encrypted) - print(f"AES Test:") + print("AES Test:") print(f"Original: {test_data}") print(f"Encrypted: {encrypted}") print(f"Decrypted: {decrypted}") @@ -343,7 +339,7 @@ if __name__ == "__main__": encrypted_sm4 = crypto_sm4.encrypt(test_data) decrypted_sm4 = crypto_sm4.decrypt(encrypted_sm4) - print(f"SM4 Test:") + print("SM4 Test:") print(f"Original: {test_data}") print(f"Encrypted: {encrypted_sm4}") print(f"Decrypted: {decrypted_sm4}") diff --git a/rag/utils/encrypted_storage.py b/rag/utils/encrypted_storage.py index 7f9190949..19e199f4e 100644 --- a/rag/utils/encrypted_storage.py +++ b/rag/utils/encrypted_storage.py @@ -15,9 +15,8 @@ # import logging -import os from common.crypto_utils import CryptoUtil -from common.decorator import singleton +# from common.decorator import singleton class EncryptedStorageWrapper: """Encrypted storage wrapper that wraps existing storage implementations to provide transparent encryption""" @@ -66,7 +65,7 @@ class EncryptedStorageWrapper: return self.storage_impl.put(bucket, fnm, encrypted_binary, tenant_id) except Exception as e: - logging.exception(f"Failed to encrypt and store data: {bucket}/{fnm}") + logging.exception(f"Failed to encrypt and store data: {bucket}/{fnm}, error: {str(e)}") raise def get(self, bucket, fnm, tenant_id=None): @@ -96,7 +95,7 @@ class EncryptedStorageWrapper: return decrypted_binary except Exception as e: - logging.exception(f"Failed to get and decrypt data: {bucket}/{fnm}") + logging.exception(f"Failed to get and decrypt data: {bucket}/{fnm}, error: {str(e)}") raise def rm(self, bucket, fnm, tenant_id=None): @@ -260,7 +259,7 @@ def create_encrypted_storage(storage_impl, algorithm=None, key=None, encryption_ wrapper.encryption_enabled = encryption_enabled if encryption_enabled: - logging.info(f"Encryption enabled in storage wrapper") + logging.info("Encryption enabled in storage wrapper") else: logging.info("Encryption disabled in storage wrapper")