2018-09-29 09:54:16 +02:00
|
|
|
extern crate serde;
|
|
|
|
extern crate serde_json;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
extern crate actix;
|
|
|
|
extern crate actix_web;
|
|
|
|
extern crate futures;
|
2018-10-03 13:21:21 +02:00
|
|
|
extern crate uuid;
|
2018-09-29 09:54:16 +02:00
|
|
|
|
|
|
|
use actix::prelude::*;
|
|
|
|
use actix_web::{
|
2018-10-03 13:21:21 +02:00
|
|
|
http, middleware, App, AsyncResponder, FutureResponse, HttpRequest, HttpResponse, Path, State,
|
2018-09-29 09:54:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
use futures::Future;
|
|
|
|
|
2018-10-03 13:21:21 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rsidm;
|
|
|
|
use rsidm::be;
|
|
|
|
use rsidm::event;
|
|
|
|
use rsidm::log::{self, EventLog};
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:21:21 +02:00
|
|
|
fn class_list((name, state): (Path<String>, State<AppState>)) -> FutureResponse<HttpResponse> {
|
2018-09-29 09:54:16 +02:00
|
|
|
// println!("request to class_list");
|
|
|
|
state
|
|
|
|
.qe
|
|
|
|
.send(
|
2018-10-03 13:21:21 +02:00
|
|
|
// 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
|
|
|
|
event::SearchEvent::new()
|
2018-09-29 09:54:16 +02:00
|
|
|
)
|
2018-10-03 13:21:21 +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?
|
2018-10-03 13:21:21 +02:00
|
|
|
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?)
|
2018-10-03 13:21:21 +02:00
|
|
|
// 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.
|
2018-10-03 13:21:21 +02:00
|
|
|
// 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
|
2018-10-03 13:21:21 +02:00
|
|
|
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))
|
2018-10-03 13:21:21 +02:00
|
|
|
}).bind("127.0.0.1:8080")
|
|
|
|
.unwrap()
|
|
|
|
.start();
|
2018-09-29 09:54:16 +02:00
|
|
|
|
2018-10-03 13:21:21 +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!");
|
|
|
|
}
|
|
|
|
}
|