import json from enum import Enum from sqlalchemy import LargeBinary, TypeDecorator from app.utils.aes import AESCipher from app.config import settings class DeploymentType(str, Enum): DATA_CENTER = "data-center" CLOUD = "cloud" def get_aes_key() -> bytes: return settings.SECRET_KEY.encode()[:32] class AESEncryptedColumn(TypeDecorator): impl = LargeBinary def process_bind_param(self, value, dialect): if value is not None: json_str = json.dumps(value) return AESCipher(get_aes_key()).encrypt(json_str) return value def process_result_value(self, value, dialect): if value is not None: json_str = AESCipher(get_aes_key()).decrypt(value) return json.loads(json_str) return value