feat: build details route
This commit is contained in:
parent
a63979af76
commit
d6a5853d34
2 changed files with 65 additions and 0 deletions
63
src/api/v1/meta.rs
Normal file
63
src/api/v1/meta.rs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::{GIT_COMMIT_HASH, VERSION};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub struct BuildDetails {
|
||||||
|
pub version: &'static str,
|
||||||
|
pub git_commit_hash: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod routes {
|
||||||
|
pub struct Meta {
|
||||||
|
pub build_details: &'static str,
|
||||||
|
pub health: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Meta {
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
build_details: "/api/v1/meta/build",
|
||||||
|
health: "/api/v1/meta/health",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const META: routes::Meta = routes::Meta::new();
|
||||||
|
|
||||||
|
/// emmits build details of the bninary
|
||||||
|
#[actix_web_codegen_const_routes::get(path = "META.build_details")]
|
||||||
|
async fn build_details() -> impl Responder {
|
||||||
|
let build = BuildDetails {
|
||||||
|
version: VERSION,
|
||||||
|
git_commit_hash: GIT_COMMIT_HASH,
|
||||||
|
};
|
||||||
|
HttpResponse::Ok().json(build)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
|
cfg.service(build_details);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use actix_web::{http::StatusCode, test, App};
|
||||||
|
|
||||||
|
use super::services;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn build_details_works() {
|
||||||
|
let app = test::init_service(App::new().configure(services)).await;
|
||||||
|
|
||||||
|
let resp = test::call_service(
|
||||||
|
&app,
|
||||||
|
test::TestRequest::get()
|
||||||
|
.uri(super::META.build_details)
|
||||||
|
.to_request(),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,8 +2,10 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
pub mod meta;
|
||||||
pub mod webhooks;
|
pub mod webhooks;
|
||||||
|
|
||||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
webhooks::services(cfg);
|
webhooks::services(cfg);
|
||||||
|
meta::services(cfg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue