Skip to content

Commit

Permalink
Merge pull request #353 from FrankYang0529/add-version-to-healthz
Browse files Browse the repository at this point in the history
feat(healthz): add version
  • Loading branch information
thomastaylor312 committed Nov 8, 2022
2 parents 218e4f2 + 9347ac3 commit 6a4775b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/invoice/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub struct MissingParcelsResponse {
pub missing: Vec<Label>,
}

#[derive(Deserialize, Serialize)]
pub struct HealthResponse {
pub status: String,
pub version: String,
}

/// A string error message returned from the server
#[derive(Debug, Serialize, Deserialize)]
pub struct ErrorResponse {
Expand Down
3 changes: 2 additions & 1 deletion src/invoice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub(crate) use api::DeviceAuthorizationExtraFields;
pub(crate) use api::LoginParams;
#[doc(inline)]
pub use api::{
ErrorResponse, InvoiceCreateResponse, KeyOptions, MissingParcelsResponse, QueryOptions,
ErrorResponse, HealthResponse, InvoiceCreateResponse, KeyOptions, MissingParcelsResponse,
QueryOptions,
};
#[doc(inline)]
pub use bindle_spec::BindleSpec;
Expand Down
9 changes: 7 additions & 2 deletions src/server/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use warp::Filter;

use crate::{server::filters, signature::KeyRing};
use crate::{invoice::HealthResponse, server::filters, signature::KeyRing};

/// A helper function that aggregates all routes into a complete API filter. If you only wish to
/// serve specific endpoints or versions, you can assemble them with the individual submodules
Expand All @@ -22,7 +22,12 @@ where
Authn: crate::authn::Authenticator + Clone + Send + Sync + 'static,
Authz: crate::authz::Authorizer + Clone + Send + Sync + 'static,
{
let health = warp::path("healthz").map(|| "OK");
let health = warp::path("healthz").map(|| {
warp::reply::json(&HealthResponse {
status: "OK".to_string(),
version: env!("CARGO_PKG_VERSION").to_string(),
})
});

// Use an Arc to avoid a possibly expensive clone of the keyring on every API call
let wrapped_keyring = Arc::new(keyring);
Expand Down

0 comments on commit 6a4775b

Please sign in to comment.