mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 14:38:06 +08:00
feat: inner api encrypt
This commit is contained in:
22
api/core/plugin/encrypt/__init__.py
Normal file
22
api/core/plugin/encrypt/__init__.py
Normal file
@ -0,0 +1,22 @@
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
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) -> Mapping[str, Any]:
|
||||
encrypter = ProviderConfigEncrypter(
|
||||
tenant_id=tenant.id,
|
||||
config=payload.data,
|
||||
provider_type=payload.type,
|
||||
provider_identity=payload.identity,
|
||||
)
|
||||
|
||||
if payload.opt == "encrypt":
|
||||
return encrypter.encrypt(payload.data)
|
||||
else:
|
||||
return encrypter.decrypt(payload.data)
|
||||
@ -112,5 +112,7 @@ class RequestInvokeEncrypt(BaseModel):
|
||||
Request to encryption
|
||||
"""
|
||||
opt: Literal["encrypt", "decrypt"]
|
||||
type: Literal["endpoint"]
|
||||
identity: str
|
||||
data: dict = Field(default_factory=dict)
|
||||
config: Mapping[str, BasicProviderConfig] = Field(default_factory=Mapping)
|
||||
config: Mapping[str, BasicProviderConfig] = Field(default_factory=Mapping)
|
||||
Reference in New Issue
Block a user