Fix: fix CI failure.(#11837)
This commit is contained in:
parent
c00f2cdde2
commit
fc333aaa79
2 changed files with 12 additions and 17 deletions
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue