chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,45 @@
|
||||
"""Safe datasource credential metadata queries for workspace-level API callers."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from services.credentials.query import CredentialQuery
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class DatasourceCredentialMetadata:
|
||||
id: str
|
||||
name: str
|
||||
type: str
|
||||
is_default: bool
|
||||
|
||||
|
||||
class DatasourceCredentialMetadataService:
|
||||
"""List and resolve datasource credential ids without exposing credential values."""
|
||||
|
||||
def __init__(self, *, credential_query: CredentialQuery) -> None:
|
||||
self._credential_query = credential_query
|
||||
|
||||
def list(self, *, tenant_id: str, plugin_id: str, provider: str) -> list[DatasourceCredentialMetadata]:
|
||||
# Dataset Service API keys and the KnowledgeFS bridge are workspace principals, not
|
||||
# account principals. Match datasource runtime binding, which is tenant-scoped.
|
||||
rows = self._credential_query.list_datasources(
|
||||
workspace_id=tenant_id,
|
||||
plugin_id=plugin_id,
|
||||
provider=provider,
|
||||
actor_id=None,
|
||||
)
|
||||
credentials = [
|
||||
DatasourceCredentialMetadata(
|
||||
id=row.id,
|
||||
name=row.name,
|
||||
type=row.auth_type,
|
||||
is_default=row.is_default,
|
||||
)
|
||||
for row in rows
|
||||
]
|
||||
return sorted(credentials, key=lambda item: (not item.is_default, item.name.casefold(), item.id))
|
||||
|
||||
def resolve_default(self, *, tenant_id: str, plugin_id: str, provider: str) -> DatasourceCredentialMetadata | None:
|
||||
credentials = self.list(tenant_id=tenant_id, plugin_id=plugin_id, provider=provider)
|
||||
fallback = credentials[0] if credentials else None
|
||||
return next((credential for credential in credentials if credential.is_default), fallback)
|
||||
Reference in new issue
Block a user