From ed53fbc9097370feeda1c5507878933643a9bcc5 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sat, 10 Apr 2021 14:16:41 +0300 Subject: Trying to auth --- src/routes.rs | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src/routes.rs') diff --git a/src/routes.rs b/src/routes.rs index 95138e6..499ba35 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,8 +1,9 @@ use warp::{Filter, Rejection, Reply}; +use crate::auth::with_auth; use crate::custom_filters; use crate::handlers; -use crate::schema::Db; +use crate::schema::{Db, Transaction}; /// Root, all routes combined pub fn consensus_routes(db: Db) -> impl Filter + Clone { @@ -14,7 +15,8 @@ pub fn consensus_routes(db: Db) -> impl Filter impl Filter + Clone { - warp::path!("transaction") + warp::path("transaction") + .and(warp::path::end()) .and(warp::get()) .and(custom_filters::with_db(db)) .and_then(handlers::list_transactions) @@ -30,13 +32,43 @@ pub fn block_list(db: Db) -> impl Filter impl Filter + Clone { - warp::path!("transaction") + warp::path("transaction") + .and(warp::path::end()) .and(warp::post()) .and(custom_filters::transaction_json_body()) .and(custom_filters::with_db(db)) .and_then(handlers::propose_transaction) } +/// POST /transaction warp route with authentication +pub fn authenticated_transaction_propose( + db: Db, +) -> impl Filter + Clone { + warp::path("transaction") + .and(warp::path::end()) + .and(warp::post()) + .and(custom_filters::transaction_json_body()) + .map(|t: Transaction| { + with_auth(db.clone(), t) + }) + .untuple_one() + .and(custom_filters::transaction_json_body()) + .and(custom_filters::with_db(db)) + .and_then(handlers::propose_authenticated_transaction) + + // .and(custom_filters::transaction_json_body()) + // // TODO: you might have to restore this + // // what we're trying to do is knowing which public key to use to decode the jwt in the + // // header of the request, we will either request it through a header (ugly, ugh) or get it + // // from json (then how do we chain these ugh) or we can just validate/check (move the + // // header/jwt logic to propose_transaction but that doesn't feel right either + // // good luck <10-04-21, yigit> // + // .map(|t: Transaction| with_auth(db.clone(), t)) + // .and(custom_filters::transaction_json_body()) + // .and(custom_filters::with_db(db)) + // .and_then(handlers::propose_transaction) +} + /// POST /block warp route pub fn block_propose(db: Db) -> impl Filter + Clone { warp::path!("block") -- cgit v1.2.3-70-g09d2