|
|
|
@ -10,12 +10,14 @@ use env_logger; |
|
|
|
|
use u_lib::{ |
|
|
|
|
MASTER_PORT, |
|
|
|
|
contracts::*, |
|
|
|
|
client::network::Paths |
|
|
|
|
}; |
|
|
|
|
use uuid::Uuid; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_content() -> impl Filter<Extract = (Message<'static, ClientInfo>,), |
|
|
|
|
fn get_content<M: ToMsg>() -> impl Filter<Extract = (Message<'static, M>,), |
|
|
|
|
Error = Rejection> + Clone { |
|
|
|
|
body::content_length_limit(1024*64).and(body::json::<Message<ClientInfo>>()) |
|
|
|
|
body::content_length_limit(1024*64).and(body::json::<Message<M>>()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -26,22 +28,49 @@ async fn main() { |
|
|
|
|
let db = warp::any().map(move || base_db.clone()); |
|
|
|
|
|
|
|
|
|
let new_client = warp::post() |
|
|
|
|
.and(warp::path("init")) |
|
|
|
|
.and(get_content()) |
|
|
|
|
.and(warp::path(Paths::init)) |
|
|
|
|
.and(get_content::<ClientInfo>()) |
|
|
|
|
.and(db.clone()) |
|
|
|
|
.and_then(handlers::add_client); |
|
|
|
|
|
|
|
|
|
let ls = warp::get() |
|
|
|
|
.and(warp::path("ls")) |
|
|
|
|
.and(warp::path(Paths::ls)) |
|
|
|
|
.and(db.clone()) |
|
|
|
|
.and_then(handlers::listing); |
|
|
|
|
|
|
|
|
|
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::<JobStorageWrapper>()) |
|
|
|
|
.and(db.clone()) |
|
|
|
|
.and_then(handlers::set_jobs); |
|
|
|
|
|
|
|
|
|
let update_own_jobs = warp::post() |
|
|
|
|
.and(warp::path(Paths::set_jobs)) |
|
|
|
|
.and(warp::path::param::<Uuid>().map(Some)) |
|
|
|
|
.and(get_content::<JobStorageWrapper>()) |
|
|
|
|
.and(db.clone()) |
|
|
|
|
.and_then(handlers::set_jobs); |
|
|
|
|
|
|
|
|
|
let auth_token = warp::header::exact("authorization", "Bearer 123qwe"); |
|
|
|
|
|
|
|
|
|
let auth_zone = auth_token.and(ls); |
|
|
|
|
let agent_zone = new_client |
|
|
|
|
.or(get_jobs) |
|
|
|
|
.or(update_own_jobs) |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
let auth_zone = auth_token |
|
|
|
|
.and(ls |
|
|
|
|
.or(set_jobs) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
let routes = new_client |
|
|
|
|
.or(auth_zone) |
|
|
|
|
let routes = auth_zone |
|
|
|
|
.or(agent_zone) |
|
|
|
|
.with(warp::log("warp")); |
|
|
|
|
warp::serve(routes) |
|
|
|
|
.run(([0,0,0,0], MASTER_PORT)).await; |
|
|
|
|