mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
fix(agent): authenticate agent control plane (#40737)
This commit is contained in:
1 parent
e2852524be
commit
3cd23d4ef8
16 files changed
+131
-31
No files matched your search
@@ -18,7 +18,7 @@ from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import httpx
|
||||
from fastapi import FastAPI
|
||||
from fastapi import APIRouter, FastAPI
|
||||
from redis.asyncio import Redis
|
||||
|
||||
from dify_agent.agent_stub.shell_env import ShellAgentStubTokenFactory
|
||||
@@ -132,16 +132,14 @@ def create_app(settings: ServerSettings | None = None) -> FastAPI:
|
||||
def get_scheduler() -> RunScheduler:
|
||||
return state["scheduler"] # pyright: ignore[reportReturnType]
|
||||
|
||||
app.include_router(
|
||||
create_runs_router(
|
||||
get_store,
|
||||
get_scheduler,
|
||||
auth_dependency=create_bearer_token_dependency(resolved_settings.api_token),
|
||||
)
|
||||
control_plane_router = APIRouter(
|
||||
dependencies=[create_bearer_token_dependency(resolved_settings.api_token)],
|
||||
)
|
||||
app.include_router(create_execution_bindings_router(lambda: execution_binding_service))
|
||||
app.include_router(create_home_snapshots_router(lambda: home_snapshot_service))
|
||||
app.include_router(create_binding_files_router(lambda: binding_file_service))
|
||||
control_plane_router.include_router(create_runs_router(get_store, get_scheduler))
|
||||
control_plane_router.include_router(create_execution_bindings_router(lambda: execution_binding_service))
|
||||
control_plane_router.include_router(create_home_snapshots_router(lambda: home_snapshot_service))
|
||||
control_plane_router.include_router(create_binding_files_router(lambda: binding_file_service))
|
||||
app.include_router(control_plane_router)
|
||||
app.include_router(
|
||||
create_agent_stub_router(
|
||||
token_codec=agent_stub_token_codec,
|
||||
|
||||
@@ -14,7 +14,6 @@ from collections.abc import Callable
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException, Query
|
||||
from fastapi.params import Depends as DependsInstance
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from dify_agent.protocol.schemas import (
|
||||
@@ -33,11 +32,8 @@ from dify_agent.storage.redis_run_store import RedisRunStore, RunNotFoundError
|
||||
def create_runs_router(
|
||||
get_store: Callable[[], RedisRunStore],
|
||||
get_scheduler: Callable[[], RunScheduler],
|
||||
*,
|
||||
auth_dependency: DependsInstance | None = None,
|
||||
) -> APIRouter:
|
||||
dependencies: list[DependsInstance] = [auth_dependency] if auth_dependency is not None else []
|
||||
router = APIRouter(prefix="/runs", tags=["runs"], dependencies=dependencies)
|
||||
router = APIRouter(prefix="/runs", tags=["runs"])
|
||||
|
||||
async def store_dep() -> RedisRunStore:
|
||||
return get_store()
|
||||
|
||||
@@ -149,14 +149,13 @@ class ServerSettings(BaseSettings):
|
||||
raise ValueError("DIFY_AGENT_INNER_API_URL must not include a query string or fragment")
|
||||
return parsed
|
||||
|
||||
@field_validator("inner_api_key")
|
||||
@field_validator("inner_api_key", "api_token")
|
||||
@classmethod
|
||||
def normalize_inner_api_key(cls, value: str | None) -> str | None:
|
||||
"""Normalize the optional trusted Dify inner API key."""
|
||||
def normalize_optional_api_token(cls, value: str | None) -> str | None:
|
||||
"""Normalize optional API authentication tokens."""
|
||||
if value is None:
|
||||
return None
|
||||
stripped = value.strip()
|
||||
return stripped or None
|
||||
return value.strip() or None
|
||||
|
||||
def get_shell_redact_patterns(self) -> list[str]:
|
||||
"""Parse the JSON array from shell_redact_patterns; empty/blank → empty list."""
|
||||
|
||||
Reference in new issue
Block a user