mz_environmentd/http/
catalog.rs
1use axum::response::IntoResponse;
13use axum_extra::TypedHeader;
14use headers::ContentType;
15use http::StatusCode;
16
17use crate::http::AuthedClient;
18
19pub async fn handle_catalog_dump(client: AuthedClient) -> impl IntoResponse {
20 match client.client.dump_catalog().await.map(|c| c.into_string()) {
21 Ok(res) => Ok((TypedHeader(ContentType::json()), res)),
22 Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
23 }
24}
25
26pub async fn handle_catalog_check(client: AuthedClient) -> impl IntoResponse {
27 let response = match client.client.check_catalog().await {
28 Ok(_) => serde_json::Value::String("".to_string()),
29 Err(inconsistencies) => serde_json::json!({ "err": inconsistencies }),
30 };
31 (TypedHeader(ContentType::json()), response.to_string())
32}
33
34pub async fn handle_coordinator_check(client: AuthedClient) -> impl IntoResponse {
35 let response = match client.client.check_coordinator().await {
36 Ok(_) => serde_json::Value::String("".to_string()),
37 Err(inconsistencies) => serde_json::json!({ "err": inconsistencies }),
38 };
39 (TypedHeader(ContentType::json()), response.to_string())
40}
41
42pub async fn handle_coordinator_dump(client: AuthedClient) -> impl IntoResponse {
43 let (status, result) = match client.client.dump_coordinator_state().await {
44 Ok(dump) => (StatusCode::OK, dump),
45 Err(e) => (
46 StatusCode::INTERNAL_SERVER_ERROR,
47 serde_json::json!({ "err": e.to_string() }),
48 ),
49 };
50 (status, TypedHeader(ContentType::json()), result.to_string())
51}