-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afa80fb
commit c67d25f
Showing
17 changed files
with
168 additions
and
199 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::fmt; | ||
use std::task::{Context, Poll}; | ||
|
||
use futures::future::Either; | ||
use quickwit_common::tower::RpcName; | ||
use tower::{Layer, Service}; | ||
|
||
use crate::AuthorizationError; | ||
|
||
pub struct AuthorizationLayer; | ||
|
||
impl<S: Clone> Layer<S> for AuthorizationLayer { | ||
type Service = AuthorizationService<S>; | ||
|
||
fn layer(&self, service: S) -> Self::Service { | ||
AuthorizationService { service } | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct AuthorizationService<S> { | ||
service: S, | ||
} | ||
|
||
impl<S, Request> Service<Request> for AuthorizationService<S> | ||
where | ||
S: Service<Request>, | ||
S::Future: Send + 'static, | ||
S::Response: Send + 'static, | ||
S::Error: From<AuthorizationError> + Send + 'static, | ||
Request: fmt::Debug + Send + RpcName + crate::Authorization + 'static, | ||
{ | ||
type Response = S::Response; | ||
type Error = S::Error; | ||
type Future = | ||
futures::future::Either<futures::future::Ready<Result<S::Response, S::Error>>, S::Future>; | ||
|
||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
self.service.poll_ready(cx) | ||
} | ||
|
||
fn call(&mut self, request: Request) -> Self::Future { | ||
if let Err(authorization_err) = crate::authorize_request(&request) { | ||
let err = S::Error::from(authorization_err); | ||
let result: Result<S::Response, S::Error> = Err(err); | ||
return Either::Left(futures::future::ready(result)); | ||
} | ||
let service_fut = self.service.call(request); | ||
Either::Right(service_fut) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
quickwit/quickwit-proto/src/codegen/quickwit/quickwit.cluster.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.