mz_environmentd/http/
catalog.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apach
9
10//! Catalog introspection HTTP endpoints.
11
12use 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}