You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.5 KiB

mod handlers;
mod db;
mod errors;
4 years ago
use warp::{
4 years ago
Filter,
Rejection,
Reply,
4 years ago
body
4 years ago
};
4 years ago
#[macro_use]
extern crate log;
extern crate env_logger;
4 years ago
4 years ago
use u_lib::{
MASTER_PORT,
api::Paths,
models::*
4 years ago
};
use db::*;
use serde::{
de::DeserializeOwned
};
fn get_content<M>()
-> impl Filter<Extract = (BaseMessage<'static, M>,),
Error = Rejection> + Clone
where
M: ToMsg + Sync + Send + DeserializeOwned + 'static
{
body::content_length_limit(1024*64)
.and(body::json::<BaseMessage<M>>())
4 years ago
}
4 years ago
#[tokio::main]
async fn main() {
env_logger::init();
4 years ago
let base_db = UDB::new().unwrap();
let db = warp::any().map(move || base_db.clone());
4 years ago
let new_client = warp::post()
.and(warp::path(Paths::init))
4 years ago
.and(get_content::<IAgent>())
.and(db.clone())
.and_then(handlers::add_agent);
let get_agents = warp::get()
4 years ago
.and(warp::path(Paths::ls))
.and(db.clone())
.and_then(handlers::get_agents);
/*
let upload_job = warp::post()
.and(warp::path(Paths::upload_job))
.and(db.clone())
.and_then(handlers::upload_job);
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(get_agents
// .or(upload_job)
// .or(set_jobs)
// .or(get_job_results)
4 years ago
)
;
4 years ago
let routes = auth_zone
4 years ago
.or(agent_zone);
warp::serve(routes.with(warp::log("warp")))
4 years ago
.run(([0,0,0,0], MASTER_PORT)).await;
4 years ago
}
#[cfg(test)]
mod tests {
use super::*;
/*
#[tokio::test]
async fn test_gather() {
}
*/
}