Skip to content

Commit

Permalink
feat: mvp status endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Christina Sørensen <[email protected]>
  • Loading branch information
cafkafk committed Apr 29, 2024
1 parent 4a93bfb commit 73695a1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rust-version = "1.77.2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = { version = "0.7.4", features = ["macros", "original-uri"] }
axum = { version = "0.7.4", features = ["macros", "original-uri", "json"] }
bytes = "1.5.0"
clap = { version = "4.5.1", features = ["cargo"] }
form_urlencoded = "1.2.1"
Expand Down
2 changes: 2 additions & 0 deletions src/api/ha_registry/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
// SPDX-License-Identifier: AGPL-3.0-only

pub mod routes;

mod status;
4 changes: 3 additions & 1 deletion src/api/ha_registry/v1/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

use axum::{routing::get, Router};

use super::status::{self, handlers::status};

pub fn get_routes() -> Router {
Router::new().route("/status", get(|| async { "working" }))
Router::new().route("/status", get(status))
}
17 changes: 17 additions & 0 deletions src/api/ha_registry/v1/status/handlers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 Christina Sørensen
// SPDX-FileContributor: Christina Sørensen
//
// SPDX-License-Identifier: AGPL-3.0-only

use crate::data::status::{Status, ServerState};
use axum::{Json, http::StatusCode};

const TEST_STATUS: Status = Status { server_state: ServerState::Healthy };

/// Handler for returning the server status.
pub async fn status() -> Result<Json<Status>, StatusCode> {
Ok(Json(TEST_STATUS))
}
// pub async fn status() -> StatusCode {
// StatusCode::OK
// }
1 change: 1 addition & 0 deletions src/api/ha_registry/v1/status/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod handlers;
5 changes: 4 additions & 1 deletion src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// SPDX-FileCopyrightText: 2023 Christina Sørensen
// SPDX-FileCopyrightText: 2024 Christina Sørensen
// SPDX-FileContributor: Christina Sørensen
//
// SPDX-License-Identifier: AGPL-3.0-only

pub mod status;

mod config;

pub use self::config::{Config, CONFIG};
27 changes: 27 additions & 0 deletions src/data/status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2024 Christina Sørensen
// SPDX-FileContributor: Christina Sørensen
//
// SPDX-License-Identifier: AGPL-3.0-only

use serde::{Deserialize, Serialize};

/// The state of the server.
///
/// - Healthy: everything is working
/// - Degraded: something is broken, but ha-registry can still run
/// - Unhealthy: ha-registry is not working
///
/// May be expanded later.
#[derive(Serialize, Deserialize)]
pub enum ServerState {
Healthy,
Degraded,
Unhealthy,
}

/// Status struct exposed over status endpoint. Used to see the current state of
/// ha-registry.
#[derive(Serialize, Deserialize)]
pub struct Status {
pub server_state: ServerState,
}

0 comments on commit 73695a1

Please sign in to comment.