kanidm/src/main.rs

117 lines
3.1 KiB
Rust
Raw Normal View History

2018-09-29 09:54:16 +02:00
extern crate serde;
extern crate serde_json;
// #[macro_use]
2018-09-29 09:54:16 +02:00
extern crate actix;
extern crate actix_web;
extern crate futures;
extern crate serde_derive;
extern crate uuid;
2018-09-29 09:54:16 +02:00
// use actix::prelude::*;
2018-09-29 09:54:16 +02:00
use actix_web::{
http, App, AsyncResponder, FutureResponse, HttpRequest, HttpResponse, Path, State,
2018-09-29 09:54:16 +02:00
};
use futures::Future;
#[macro_use]
extern crate rsidm;
use rsidm::event;
use rsidm::filter::Filter;
use rsidm::log;
use rsidm::server;
2018-09-29 09:54:16 +02:00
struct AppState {
qe: actix::Addr<server::QueryServer>,
}
// Handle the various end points we need to expose
/// simple handle
fn index(req: &HttpRequest<AppState>) -> HttpResponse {
println!("{:?}", req);
HttpResponse::Ok().body("Hello\n")
}
fn class_list((_name, state): (Path<String>, State<AppState>)) -> FutureResponse<HttpResponse> {
2018-09-29 09:54:16 +02:00
// println!("request to class_list");
let filt = Filter::Pres(String::from("objectclass"));
2018-09-29 09:54:16 +02:00
state
.qe
.send(
// This is where we need to parse the request into an event
// LONG TERM
// Make a search REQUEST, and create the audit struct here, then
// pass it to the server
//
// FIXME: Don't use SEARCHEVENT here!!!!
//
event::SearchEvent::new(filt),
2018-09-29 09:54:16 +02:00
)
// TODO: How to time this part of the code?
2018-09-29 09:54:16 +02:00
// What does this do?
.from_err()
.and_then(|res| match res {
// What type is entry?
Ok(event::EventResult::Search { entries }) => Ok(HttpResponse::Ok().json(entries)),
Ok(_) => Ok(HttpResponse::Ok().into()),
2018-09-29 09:54:16 +02:00
// Can we properly report this?
Err(_) => Ok(HttpResponse::InternalServerError().into()),
})
// What does this do?
.responder()
}
fn main() {
let sys = actix::System::new("rsidm-server");
// read the config (if any?)
// How do we make the config accesible to all threads/workers? clone it?
// Make it an Arc<Config>?
2018-09-29 09:54:16 +02:00
// Until this point, we probably want to write to stderr
// Start up the logging system: for now it just maps to stderr
let log_addr = log::start();
// Starting the BE chooses the path.
// let be_addr = be::start(log_addr.clone(), be::BackendType::SQLite, "test.db", 8);
2018-09-29 09:54:16 +02:00
// Start the query server with the given be
let server_addr = server::start(log_addr.clone(), "test.db", 8);
2018-09-29 09:54:16 +02:00
// start the web server
actix_web::server::new(move || {
App::with_state(AppState {
qe: server_addr.clone(),
})
// Connect all our end points here.
// .middleware(middleware::Logger::default())
.resource("/", |r| r.f(index))
.resource("/{class_list}", |r| {
r.method(http::Method::GET).with(class_list)
})
.resource("/{class_list}/", |r| {
r.method(http::Method::GET).with(class_list)
})
})
.bind("127.0.0.1:8080")
.unwrap()
.start();
2018-09-29 09:54:16 +02:00
log_event!(log_addr, "Starting rsidm on http://127.0.0.1:8080");
2018-09-29 09:54:16 +02:00
// all the needed routes / views
let _ = sys.run();
}
#[cfg(test)]
mod tests {
#[test]
fn test_simple_create() {
println!("It works!");
}
}