From 38a928a47f94d9f456c9c53f5db4fcd19165e7ac Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sat, 10 Apr 2021 15:14:37 +0300 Subject: agliyo --- src/auth.rs | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) (limited to 'src/auth.rs') diff --git a/src/auth.rs b/src/auth.rs index ced9e8e..03930f0 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -63,29 +63,10 @@ struct Claims { puk: String, } -// #[derive(Error, Debug)] -// pub enum Nope { -// #[error("Invalid header")] -// InvalidHeader { -// expected: String, -// found: String, -// }, -// } -// impl warp::reject::Reject for Nope {} +#[derive(Debug)] +struct RateLimited; -#[derive(Error, Debug)] -pub enum DataStoreError { - #[error("invalid header")] - InvalidHeader {}, -} - -impl Reject for DataStoreError {} - -// impl From for Rejection { -// fn from(other: LessThanTenError) -> Self { -// warp::reject::custom(other) -// } -// } +impl Reject for RateLimited {} pub fn with_auth( db: Db, @@ -94,10 +75,9 @@ pub fn with_auth( headers_cloned() .map(move |headers: HeaderMap| (db.clone(), headers)) .and_then(authorize) - .recover(handle_rejection()) } -async fn authorize((db, headers): (Db, HeaderMap)) -> Result { +async fn authorize((db, headers): (Db, HeaderMap)) -> Result { match jwt_from_header(&headers) { Ok(jwt) => { let decoded = decode::( @@ -111,8 +91,7 @@ async fn authorize((db, headers): (Db, HeaderMap)) -> Result return (StatusCode::UNAUTHORIZED, e.to_string()), - // warp error + Err(e) => return Err(warp::reject::custom(RateLimited)), } } -- cgit v1.2.3-70-g09d2