mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-11-27 15:53:46 +00:00
add redis to health check
This commit is contained in:
parent
055ce540c6
commit
3132a48087
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -1798,14 +1798,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.95"
|
version = "0.2.97"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36"
|
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libmcaptcha"
|
name = "libmcaptcha"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
source = "git+https://github.com/mCaptcha/libmcaptcha?branch=master#1c6e9dd01d6fbb2931cfafca680583005bf9fd0e"
|
source = "git+https://github.com/mCaptcha/libmcaptcha?branch=master#3db009977ae4144b0a3f71dbb310f62f11c31893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix",
|
"actix",
|
||||||
"derive_builder 0.9.0",
|
"derive_builder 0.9.0",
|
||||||
@ -2469,7 +2469,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"rand_chacha 0.3.0",
|
"rand_chacha 0.3.1",
|
||||||
"rand_core 0.6.2",
|
"rand_core 0.6.2",
|
||||||
"rand_hc 0.3.0",
|
"rand_hc 0.3.0",
|
||||||
]
|
]
|
||||||
@ -2486,9 +2486,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_chacha"
|
name = "rand_chacha"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ppv-lite86",
|
"ppv-lite86",
|
||||||
"rand_core 0.6.2",
|
"rand_core 0.6.2",
|
||||||
@ -3175,9 +3175,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.72"
|
version = "1.0.73"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82"
|
checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|||||||
@ -77,3 +77,7 @@ mime = "0.3.16"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256" }
|
pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256" }
|
||||||
|
|
||||||
|
|
||||||
|
[target.x86_64-unknown-linux-musl]
|
||||||
|
linker = "x86_64"
|
||||||
|
|||||||
@ -18,9 +18,11 @@
|
|||||||
use actix_web::{web, HttpResponse, Responder};
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use libmcaptcha::redis::{Redis, RedisConfig};
|
||||||
|
|
||||||
use crate::AppData;
|
use crate::AppData;
|
||||||
use crate::{GIT_COMMIT_HASH, VERSION};
|
use crate::{GIT_COMMIT_HASH, VERSION};
|
||||||
|
use crate::data::SystemGroup;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Builder, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Builder, Serialize)]
|
||||||
pub struct BuildDetails {
|
pub struct BuildDetails {
|
||||||
@ -58,6 +60,14 @@ async fn build_details() -> impl Responder {
|
|||||||
/// Health check return datatype
|
/// Health check return datatype
|
||||||
pub struct Health {
|
pub struct Health {
|
||||||
db: bool,
|
db: bool,
|
||||||
|
#[serde(skip_serializing_if = "Self::is_redis")]
|
||||||
|
redis: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Health {
|
||||||
|
fn is_redis(redis: &Option<bool>) -> bool {
|
||||||
|
redis.is_none()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// checks all components of the system
|
/// checks all components of the system
|
||||||
@ -67,12 +77,32 @@ async fn health(data: AppData) -> impl Responder {
|
|||||||
|
|
||||||
let mut resp_builder = HealthBuilder::default();
|
let mut resp_builder = HealthBuilder::default();
|
||||||
resp_builder.db(false);
|
resp_builder.db(false);
|
||||||
|
if resp_builder.redis.is_none() {
|
||||||
|
//
|
||||||
|
};
|
||||||
|
|
||||||
if let Ok(mut con) = data.db.acquire().await {
|
if let Ok(mut con) = data.db.acquire().await {
|
||||||
if con.ping().await.is_ok() {
|
if con.ping().await.is_ok() {
|
||||||
resp_builder.db(true);
|
resp_builder.db(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
match data.captcha {
|
||||||
|
SystemGroup::Redis(_) => {
|
||||||
|
let r = Redis::new(RedisConfig::Single(crate::SETTINGS.redis.as_ref().unwrap().url.clone())).await.unwrap();
|
||||||
|
let status = r.get_client().ping().await;
|
||||||
|
resp_builder.redis = Some(Some(status));
|
||||||
|
|
||||||
|
|
||||||
|
// unimplemented!("GET PING FROM REDIS")
|
||||||
|
//redis.get
|
||||||
|
|
||||||
|
},
|
||||||
|
SystemGroup::Embedded(_) => {
|
||||||
|
resp_builder.redis = None;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
HttpResponse::Ok().json(resp_builder.build().unwrap())
|
HttpResponse::Ok().json(resp_builder.build().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,5 +150,6 @@ mod tests {
|
|||||||
|
|
||||||
let health_resp: Health = test::read_body_json(resp).await;
|
let health_resp: Health = test::read_body_json(resp).await;
|
||||||
assert_eq!(health_resp.db, true);
|
assert_eq!(health_resp.db, true);
|
||||||
|
assert_eq!(health_resp.redis, Some(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user