mirror of
https://github.com/langgenius/dify.git
synced 2026-05-28 21:03:22 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: EvanYao826 <155432245+EvanYao826@users.noreply.github.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: 盐粒 Yanli <yanli@dify.ai> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Tianle <40735546+Tianlel@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai> Co-authored-by: zyssyz123 <916125788@qq.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: chariri <w@chariri.moe> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Nian <11332799+Lillian68@users.noreply.github.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Carmen Fernández Ruiz <279459669+zeus1959@users.noreply.github.com> Co-authored-by: wangxiaolei <fatelei@gmail.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: L1nSn0w <l1nsn0w@qq.com> Co-authored-by: Evan <2869018789@qq.com> Co-authored-by: Escape0707 <tothesong@gmail.com> Co-authored-by: Jingyi <jingyi.qi@dify.ai> Co-authored-by: Amr Sherif <140330826+amr-sheriff@users.noreply.github.com> Co-authored-by: ZHOU ZHICHEN <118870511+zhuiguangzhe2003@users.noreply.github.com> Co-authored-by: unknown <EI05187@apwx.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import uuid
|
|
from enum import StrEnum
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
from werkzeug.exceptions import InternalServerError
|
|
|
|
from configs import dify_config
|
|
from libs.oauth_bearer import Scope, TokenType
|
|
from models.account import Account, Tenant
|
|
from models.model import App, EndUser
|
|
from services.enterprise.enterprise_service import WebAppAccessMode
|
|
|
|
|
|
class Edition(StrEnum):
|
|
CE = "ce"
|
|
EE = "ee"
|
|
SAAS = "saas"
|
|
|
|
|
|
def current_edition() -> Edition:
|
|
if dify_config.EDITION == "CLOUD":
|
|
return Edition.SAAS
|
|
if dify_config.ENTERPRISE_ENABLED:
|
|
return Edition.EE
|
|
return Edition.CE
|
|
|
|
|
|
class ExternalIdentity(BaseModel):
|
|
model_config = ConfigDict(frozen=True)
|
|
|
|
email: str
|
|
issuer: str | None = None
|
|
|
|
|
|
class RequestContext(BaseModel):
|
|
model_config = ConfigDict(frozen=True)
|
|
|
|
token_type: TokenType
|
|
scope: Scope | None = None
|
|
path_params: dict[str, str]
|
|
|
|
|
|
class AuthData(BaseModel):
|
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
|
|
required_scope: Scope | None = None
|
|
token_type: TokenType
|
|
account_id: uuid.UUID | None = None
|
|
token_hash: str
|
|
token_id: uuid.UUID | None = None
|
|
scopes: frozenset[Scope]
|
|
tenants: dict[str, bool] = Field(default_factory=dict)
|
|
external_identity: ExternalIdentity | None = None
|
|
path_params: dict[str, str] = Field(default_factory=dict)
|
|
|
|
app: App | None = None
|
|
tenant: Tenant | None = None
|
|
app_access_mode: WebAppAccessMode | None = None
|
|
|
|
caller: Account | EndUser | None = None
|
|
caller_kind: Literal["account", "end_user"] | None = None
|
|
|
|
def require_app_context(self) -> tuple[App, Account | EndUser, Literal["account", "end_user"]]:
|
|
if self.app is None or self.caller is None or self.caller_kind is None:
|
|
raise InternalServerError("pipeline_invariant_violated: app context missing")
|
|
return self.app, self.caller, self.caller_kind
|