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