mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 01:47:47 +08:00
refactor: 移除独立 hub/proxy/executor/gateway crate,统一为 gateway tunnel 架构
- 删除 aether-hub、aether-proxy 独立项目及其 Dockerfile/配置 - 删除 crates/aether-executor 和 crates/aether-gateway 全部模块 - 新增 apps/ 目录作为应用入口 - 将 hub 概念重构为 gateway tunnel transport - 将 executor 重构为 execution runtime - 新增 tunnel.rs 合约定义和 testkit tunnel/execution_runtime 模块 - 更新 Python 服务层和测试适配新架构命名
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
use axum::body::{Body, Bytes};
|
||||
use axum::http::{HeaderName, HeaderValue, Response};
|
||||
|
||||
use crate::gateway::constants::CONTROL_EXECUTED_HEADER;
|
||||
use crate::gateway::{AppState, GatewayControlDecision, GatewayError};
|
||||
|
||||
use super::resolve_execution_runtime_auth_context;
|
||||
|
||||
pub(crate) fn allows_control_execute_emergency(decision: &GatewayControlDecision) -> bool {
|
||||
decision.is_execution_runtime_candidate()
|
||||
}
|
||||
|
||||
pub(crate) async fn maybe_execute_via_control(
|
||||
state: &AppState,
|
||||
parts: &http::request::Parts,
|
||||
body_bytes: Bytes,
|
||||
trace_id: &str,
|
||||
decision: Option<&GatewayControlDecision>,
|
||||
require_stream: bool,
|
||||
) -> Result<Option<Response<Body>>, GatewayError> {
|
||||
let Some(decision) = decision else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let mut local_decision = decision.clone();
|
||||
if let Some(auth_context) = resolve_execution_runtime_auth_context(
|
||||
state,
|
||||
&local_decision,
|
||||
&parts.headers,
|
||||
&parts.uri,
|
||||
trace_id,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
local_decision.auth_context = Some(auth_context);
|
||||
local_decision.local_auth_rejection = None;
|
||||
}
|
||||
|
||||
let response = if require_stream {
|
||||
crate::gateway::maybe_execute_via_execution_runtime_stream(
|
||||
state,
|
||||
parts,
|
||||
&body_bytes,
|
||||
trace_id,
|
||||
Some(&local_decision),
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
crate::gateway::maybe_execute_via_execution_runtime_sync(
|
||||
state,
|
||||
parts,
|
||||
&body_bytes,
|
||||
trace_id,
|
||||
Some(&local_decision),
|
||||
)
|
||||
.await?
|
||||
};
|
||||
|
||||
Ok(response.map(mark_control_executed))
|
||||
}
|
||||
|
||||
fn mark_control_executed(mut response: Response<Body>) -> Response<Body> {
|
||||
response.headers_mut().insert(
|
||||
HeaderName::from_static(CONTROL_EXECUTED_HEADER),
|
||||
HeaderValue::from_static("true"),
|
||||
);
|
||||
response
|
||||
}
|
||||
Reference in New Issue
Block a user