Skip to content

Commit

Permalink
Merge branch 'master' into abstract-backend
Browse files Browse the repository at this point in the history
Resolves merge conflict
  • Loading branch information
dienummer committed Jan 25, 2024
2 parents 0bd80dd + ff51875 commit e1dee95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const ALLOWED_ORIGINS: [&str; 6] = [
const ALLOWED_SUBDOMAIN: &str = ".mutiny-web.pages.dev";
const ALLOWED_LOCALHOST: &str = "http://127.0.0.1:";

const API_VERSION: &str = "v2";

#[derive(Clone)]
pub struct State {
backend: Arc<dyn models::backend::VssBackend>,
Expand Down
24 changes: 21 additions & 3 deletions src/routes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::auth::verify_token;
use crate::kv::{KeyValue, KeyValueOld};
use crate::{State, ALLOWED_LOCALHOST, ALLOWED_ORIGINS, ALLOWED_SUBDOMAIN};
use crate::{State, ALLOWED_LOCALHOST, ALLOWED_ORIGINS, ALLOWED_SUBDOMAIN, API_VERSION};
use axum::headers::authorization::Bearer;
use axum::headers::{Authorization, Origin};
use axum::http::StatusCode;
Expand Down Expand Up @@ -205,8 +205,26 @@ pub async fn list_key_versions(
}
}

pub async fn health_check() -> Result<Json<()>, (StatusCode, String)> {
Ok(Json(()))
#[derive(Serialize)]
pub struct HealthResponse {
pub status: String,
pub version: String,
}

impl HealthResponse {
/// Fabricate a status: pass response without checking database connectivity
pub fn new_ok() -> Self {
Self {
status: String::from("pass"),
version: String::from(API_VERSION),
}
}
}

/// IETF draft RFC for HTTP API Health Checks:
/// https://datatracker.ietf.org/doc/html/draft-inadarei-api-health-check
pub async fn health_check() -> Result<Json<HealthResponse>, (StatusCode, String)> {
Ok(Json(HealthResponse::new_ok()))
}

pub fn valid_origin(origin: &str) -> bool {
Expand Down

0 comments on commit e1dee95

Please sign in to comment.