1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
use axum::{extract::State, response::IntoResponse};
use tonic::IntoRequest;
use warden_core::{
configuration::routing::{RoutingConfiguration, query_routing_server::QueryRouting},
google,
};
use crate::{
server::{error::AppError, http_svc::TAG_ROUTING, version::Version},
state::AppHandle,
};
/// Get active routing configuration
#[utoipa::path(
get,
responses((
status = OK,
body = RoutingConfiguration
)),
operation_id = "get_active_routing", // https://github.com/juhaku/utoipa/issues/1170
path = "/{version}/routing",
params(
("version" = Version, Path, description = "API version, e.g., v1, v2, v3")
),
tag = TAG_ROUTING,
)
]
#[axum::debug_handler]
#[tracing::instrument(skip(state), err(Debug), fields(method = "GET"))]
pub async fn active_routing(
version: Version,
State(state): State<AppHandle>,
) -> Result<impl IntoResponse, AppError> {
let config = state
.get_active_routing_configuration(google::protobuf::Empty::default().into_request())
.await?
.into_inner();
Ok(axum::Json(config.configuration).into_response())
}
#[cfg(test)]
mod tests {
use axum::{
body::Body,
http::{Request, StatusCode},
};
use sqlx::PgPool;
use tower::ServiceExt;
use warden_stack::cache::RedisManager;
use crate::{
server::http_svc::{build_router, routes::test_config},
state::{AppState, Services},
};
#[sqlx::test]
async fn get_empty(pool: PgPool) {
let config = test_config();
let cache = RedisManager::new(&config.cache).await.unwrap();
let client = async_nats::connect(&config.nats.hosts[0]).await.unwrap();
let jetstream = async_nats::jetstream::new(client);
let state = AppState::create(
Services {
postgres: pool,
cache,
jetstream,
},
&test_config(),
)
.await
.unwrap();
let app = build_router(state);
let response = app
.clone()
.oneshot(
Request::builder()
.method("GET")
.header("Content-Type", "application/json")
.uri("/api/v0/routing")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
}
}
|