feat: add description

This commit is contained in:
Yeuoly
2024-10-17 12:59:11 +08:00
parent 8495ed3348
commit beebcbd962
3 changed files with 2 additions and 1 deletions

View File

@ -0,0 +1,30 @@
from core.plugin.entities.request import RequestInvokeEncrypt
from core.tools.utils.configuration import ProviderConfigEncrypter
from models.account import Tenant
class PluginEncrypter:
@classmethod
def invoke_encrypt(cls, tenant: Tenant, payload: RequestInvokeEncrypt) -> dict:
encrypter = ProviderConfigEncrypter(
tenant_id=tenant.id,
config=payload.config,
provider_type=payload.namespace,
provider_identity=payload.identity,
)
if payload.opt == "encrypt":
return {
"data": encrypter.encrypt(payload.data),
}
elif payload.opt == "decrypt":
return {
"data": encrypter.decrypt(payload.data),
}
elif payload.opt == "clear":
encrypter.delete_tool_credentials_cache()
return {
"data": {},
}
else:
raise ValueError(f"Invalid opt: {payload.opt}")