mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 20:47:01 +01:00
216 - add initial /status endpoint
This commit is contained in:
parent
7687791466
commit
fa43ac2110
|
@ -241,11 +241,13 @@ async fn main() {
|
||||||
match socket_res {
|
match socket_res {
|
||||||
Ok(socket) => {
|
Ok(socket) => {
|
||||||
let cachelayer_ref = cachelayer.clone();
|
let cachelayer_ref = cachelayer.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(
|
||||||
if let Err(e) = handle_client(socket, cachelayer_ref.clone()).await {
|
async move {
|
||||||
error!("an error occured; error = {:?}", e);
|
if let Err(e) = handle_client(socket, cachelayer_ref.clone()).await {
|
||||||
}
|
error!("an error occured; error = {:?}", e);
|
||||||
});
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Accept error -> {:?}", err);
|
error!("Accept error -> {:?}", err);
|
||||||
|
|
|
@ -35,6 +35,7 @@ use crate::interval::IntervalActor;
|
||||||
use crate::schema::Schema;
|
use crate::schema::Schema;
|
||||||
use crate::schema::SchemaTransaction;
|
use crate::schema::SchemaTransaction;
|
||||||
use crate::server::QueryServer;
|
use crate::server::QueryServer;
|
||||||
|
use crate::status::{StatusActor, StatusRequestEvent};
|
||||||
use crate::utils::duration_from_epoch_now;
|
use crate::utils::duration_from_epoch_now;
|
||||||
use crate::value::PartialValue;
|
use crate::value::PartialValue;
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ use uuid::Uuid;
|
||||||
struct AppState {
|
struct AppState {
|
||||||
qe_r: Addr<QueryServerReadV1>,
|
qe_r: Addr<QueryServerReadV1>,
|
||||||
qe_w: Addr<QueryServerWriteV1>,
|
qe_w: Addr<QueryServerWriteV1>,
|
||||||
|
status: Addr<StatusActor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_current_user(session: &Session) -> Option<UserAuthToken> {
|
fn get_current_user(session: &Session) -> Option<UserAuthToken> {
|
||||||
|
@ -1024,6 +1026,16 @@ async fn idm_account_set_password(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// == Status
|
||||||
|
|
||||||
|
async fn status((_session, state): (Session, Data<AppState>)) -> HttpResponse {
|
||||||
|
let r = state.status.send(StatusRequestEvent {}).await;
|
||||||
|
match r {
|
||||||
|
Ok(true) => HttpResponse::Ok().json(true),
|
||||||
|
_ => HttpResponse::InternalServerError().json(false),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// === internal setup helpers
|
// === internal setup helpers
|
||||||
|
|
||||||
fn setup_backend(config: &Configuration) -> Result<Backend, OperationError> {
|
fn setup_backend(config: &Configuration) -> Result<Backend, OperationError> {
|
||||||
|
@ -1366,6 +1378,9 @@ pub fn create_server_core(config: Configuration) {
|
||||||
// asynchronously.
|
// asynchronously.
|
||||||
let log_addr = async_log::start();
|
let log_addr = async_log::start();
|
||||||
|
|
||||||
|
// Start the status tracking thread
|
||||||
|
let status_addr = StatusActor::start(log_addr.clone());
|
||||||
|
|
||||||
// Setup TLS (if any)
|
// Setup TLS (if any)
|
||||||
let opt_tls_params = match setup_tls(&config) {
|
let opt_tls_params = match setup_tls(&config) {
|
||||||
Ok(opt_tls_params) => opt_tls_params,
|
Ok(opt_tls_params) => opt_tls_params,
|
||||||
|
@ -1457,6 +1472,7 @@ pub fn create_server_core(config: Configuration) {
|
||||||
.data(AppState {
|
.data(AppState {
|
||||||
qe_r: server_read_addr.clone(),
|
qe_r: server_read_addr.clone(),
|
||||||
qe_w: server_write_addr.clone(),
|
qe_w: server_write_addr.clone(),
|
||||||
|
status: status_addr.clone(),
|
||||||
})
|
})
|
||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
.wrap(
|
.wrap(
|
||||||
|
@ -1489,6 +1505,7 @@ pub fn create_server_core(config: Configuration) {
|
||||||
.into()
|
.into()
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
.service(web::scope("/status").route("", web::get().to(status)))
|
||||||
.service(
|
.service(
|
||||||
web::scope("/v1/raw")
|
web::scope("/v1/raw")
|
||||||
.route("/create", web::post().to(create))
|
.route("/create", web::post().to(create))
|
||||||
|
|
|
@ -35,6 +35,7 @@ mod idm;
|
||||||
mod repl;
|
mod repl;
|
||||||
mod schema;
|
mod schema;
|
||||||
mod server;
|
mod server;
|
||||||
|
mod status;
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod core;
|
pub mod core;
|
||||||
|
|
35
kanidmd/src/lib/status.rs
Normal file
35
kanidmd/src/lib/status.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
use crate::async_log::{EventLog, LogEvent};
|
||||||
|
use actix::prelude::*;
|
||||||
|
|
||||||
|
pub struct StatusActor {
|
||||||
|
log_addr: actix::Addr<EventLog>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StatusActor {
|
||||||
|
pub fn start(log_addr: actix::Addr<EventLog>) -> actix::Addr<StatusActor> {
|
||||||
|
SyncArbiter::start(1, move || StatusActor {
|
||||||
|
log_addr: log_addr.clone(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Actor for StatusActor {
|
||||||
|
type Context = SyncContext<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct StatusRequestEvent {}
|
||||||
|
|
||||||
|
impl Message for StatusRequestEvent {
|
||||||
|
type Result = bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Handler<StatusRequestEvent> for StatusActor {
|
||||||
|
type Result = bool;
|
||||||
|
|
||||||
|
fn handle(&mut self, _event: StatusRequestEvent, _ctx: &mut SyncContext<Self>) -> Self::Result {
|
||||||
|
self.log_addr.do_send(LogEvent {
|
||||||
|
msg: "status request event: ok".to_string(),
|
||||||
|
});
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue