mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add status reporting to auth server
This commit is contained in:
@@ -64,6 +64,8 @@ async fn main() -> std::io::Result<()> {
|
||||
.service(robocraft::username::user_password_auth)
|
||||
.service(robocraft::intercom::services_ws)
|
||||
.service(robocraft::intercom::service_msg)
|
||||
.service(robocraft::intercom::status_get)
|
||||
.service(robocraft::intercom::status_set)
|
||||
})
|
||||
.bind((cli_args.ip, cli_args.port))?
|
||||
.run()
|
||||
|
||||
@@ -7,6 +7,9 @@ pub use services::{services_ws, service_msg};
|
||||
mod user_registry;
|
||||
pub use user_registry::Users;
|
||||
|
||||
mod status;
|
||||
pub use status::{status_set, status_get};
|
||||
|
||||
enum IntercomOp {
|
||||
Message(oj_rc_core::persist::user::intercom::IntercomWebServiceUserMessage),
|
||||
Info(IntercomInfo),
|
||||
|
||||
19
rc_auth/src/robocraft/intercom/status.rs
Normal file
19
rc_auth/src/robocraft/intercom/status.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use actix_web::{HttpRequest, HttpResponse, web::{Data, Path, Json}, Error, get, post};
|
||||
|
||||
#[get("/intercom/.status")]
|
||||
pub async fn status_get(reg: Data<super::Users>) -> Json<oj_serdes::Status> {
|
||||
Json(oj_serdes::Status {
|
||||
servers: reg.statuses().await
|
||||
})
|
||||
}
|
||||
|
||||
#[post("/intercom/.status/{name}/{service}")]
|
||||
pub async fn status_set(req: HttpRequest, body: Json<oj_serdes::ServerStatus>, auth: Data<super::IntercomAuth>, reg: Data<super::Users>, uri: Path<(String, String)>) -> Result<HttpResponse, Error> {
|
||||
let name = &uri.0;
|
||||
let service = &uri.1;
|
||||
log::debug!("Got intercom status message from {}/{}", name, service);
|
||||
auth.validate(&req, &format!(".status/{}/{}", name, service))?;
|
||||
log::debug!("Authenticated intercom status message from {}/{}", name, service);
|
||||
reg.save_status(service.clone(), body.clone()).await;
|
||||
Ok(HttpResponse::NoContent().finish())
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
pub struct Users {
|
||||
service_listeners: tokio::sync::RwLock<std::collections::HashMap<String, tokio::sync::mpsc::Sender<super::IntercomOp>>>,
|
||||
service_status: tokio::sync::RwLock<std::collections::HashMap<String, oj_serdes::ServerStatus>>,
|
||||
}
|
||||
|
||||
impl Users {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
service_listeners: tokio::sync::RwLock::new(std::collections::HashMap::with_capacity(16)),
|
||||
service_status: tokio::sync::RwLock::new(std::collections::HashMap::with_capacity(16)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,4 +49,12 @@ impl Users {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn statuses(&self) -> std::collections::HashMap<String, oj_serdes::ServerStatus> {
|
||||
self.service_status.read().await.clone()
|
||||
}
|
||||
|
||||
pub async fn save_status(&self, service: String, status: oj_serdes::ServerStatus) -> Option<oj_serdes::ServerStatus> {
|
||||
self.service_status.write().await.insert(service, status)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user