|
|
|
mod handlers;
|
|
|
|
mod db;
|
|
|
|
mod errors;
|
|
|
|
|
|
|
|
use warp::{
|
|
|
|
Filter,
|
|
|
|
Rejection,
|
|
|
|
Reply,
|
|
|
|
body
|
|
|
|
};
|
|
|
|
use env_logger;
|
|
|
|
use u_lib::{
|
|
|
|
MASTER_PORT,
|
|
|
|
contracts::*,
|
|
|
|
network::Paths
|
|
|
|
};
|
|
|
|
use db::*;
|
|
|
|
use serde::{
|
|
|
|
de::DeserializeOwned
|
|
|
|
};
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel;
|
|
|
|
|
|
|
|
|
|
|
|
fn get_content<M>()
|
|
|
|
-> impl Filter<Extract = (Message<'static, M>,),
|
|
|
|
Error = Rejection> + Clone
|
|
|
|
where
|
|
|
|
M: Clone + Sync + Send + DeserializeOwned + 'static
|
|
|
|
{
|
|
|
|
body::content_length_limit(1024*64)
|
|
|
|
.and(body::json::<Message<M>>())
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
env_logger::init();
|
|
|
|
|
|
|
|
let base_db = UDB::new().unwrap();
|
|
|
|
let db = warp::any().map(move || base_db.clone());
|
|
|
|
|
|
|
|
let new_client = warp::post()
|
|
|
|
.and(warp::path(Paths::init))
|
|
|
|
//.and(get_content::<IAgent>())
|
|
|
|
//.and(db.clone())
|
|
|
|
.and_then(handlers::dummy);
|
|
|
|
/*
|
|
|
|
let ls = warp::get()
|
|
|
|
.and(warp::path(Paths::ls))
|
|
|
|
.and(db.clone())
|
|
|
|
.and_then(handlers::ls);
|
|
|
|
|
|
|
|
let get_jobs = warp::get()
|
|
|
|
.and(warp::path(Paths::get_jobs))
|
|
|
|
.and(db.clone())
|
|
|
|
.and_then(handlers::get_jobs);
|
|
|
|
|
|
|
|
let set_jobs = warp::post()
|
|
|
|
.and(warp::path(Paths::set_jobs))
|
|
|
|
.and(warp::path::param::<Uuid>().map(Some))
|
|
|
|
.and(get_content::<JobMetaStorage>())
|
|
|
|
.and(db.clone())
|
|
|
|
.and_then(handlers::set_jobs);
|
|
|
|
|
|
|
|
let get_job_results = warp::get()
|
|
|
|
.and(warp::path(Paths::get_job_results))
|
|
|
|
.and(warp::path::param::<Uuid>())
|
|
|
|
.and(db.clone())
|
|
|
|
.and_then(handlers::get_job_results);
|
|
|
|
|
|
|
|
let report = warp::post()
|
|
|
|
.and(warp::path(Paths::report))
|
|
|
|
.and(get_content::<Vec<JobResult>>())
|
|
|
|
.and(db.clone())
|
|
|
|
.and_then(handlers::report);
|
|
|
|
*/
|
|
|
|
let auth_token = warp::header::exact("authorization", "Bearer 123qwe");
|
|
|
|
|
|
|
|
let agent_zone = new_client
|
|
|
|
// .or(get_jobs)
|
|
|
|
// .or(report)
|
|
|
|
;
|
|
|
|
|
|
|
|
let auth_zone = auth_token
|
|
|
|
// .and(ls
|
|
|
|
// .or(set_jobs)
|
|
|
|
// .or(get_job_results)
|
|
|
|
// )
|
|
|
|
;
|
|
|
|
|
|
|
|
let routes = auth_zone
|
|
|
|
.or(agent_zone)
|
|
|
|
.with(warp::log("warp"));
|
|
|
|
warp::serve(routes)
|
|
|
|
.run(([0,0,0,0], MASTER_PORT)).await;
|
|
|
|
}
|