forked from shuttle-hq/shuttle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[scaling] feat: builder service (shuttle-hq#999) - only test refactor
* feat: builder init * feat: build route * feat: builder service * feat: binary and docker image * refactor: clippy suggestions * refactor: move test helpers to common crate * refactor: trim deployer-alpha * refactor: get name from nbuild * refactor: .crate to .tar.gz * refactor: Cmd to Entrypoint
- Loading branch information
Showing
6 changed files
with
102 additions
and
81 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,12 @@ | ||
[package] | ||
name = "shuttle-common-tests" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
publish = false | ||
|
||
[dependencies] | ||
hyper = { workspace = true } | ||
shuttle-common = { workspace = true } | ||
tower = { workspace = true } |
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,57 @@ | ||
use shuttle_common::claims::{Claim, Scope}; | ||
|
||
/// Layer to set JwtScopes on a request. | ||
/// For use in other tests | ||
#[derive(Clone)] | ||
pub struct JwtScopesLayer { | ||
/// Thes scopes to set | ||
scopes: Vec<Scope>, | ||
} | ||
|
||
impl JwtScopesLayer { | ||
/// Create a new layer to set scopes on requests | ||
pub fn new(scopes: Vec<Scope>) -> Self { | ||
Self { scopes } | ||
} | ||
} | ||
|
||
impl<S> tower::Layer<S> for JwtScopesLayer { | ||
type Service = JwtScopes<S>; | ||
|
||
fn layer(&self, inner: S) -> Self::Service { | ||
JwtScopes { | ||
inner, | ||
scopes: self.scopes.clone(), | ||
} | ||
} | ||
} | ||
|
||
/// Middleware to set scopes on a request | ||
#[derive(Clone)] | ||
pub struct JwtScopes<S> { | ||
inner: S, | ||
scopes: Vec<Scope>, | ||
} | ||
|
||
impl<S> tower::Service<hyper::Request<hyper::Body>> for JwtScopes<S> | ||
where | ||
S: tower::Service<hyper::Request<hyper::Body>> + Send + Clone + 'static, | ||
S::Future: Send + 'static, | ||
{ | ||
type Response = S::Response; | ||
type Error = S::Error; | ||
type Future = S::Future; | ||
|
||
fn poll_ready( | ||
&mut self, | ||
cx: &mut std::task::Context<'_>, | ||
) -> std::task::Poll<Result<(), Self::Error>> { | ||
self.inner.poll_ready(cx) | ||
} | ||
|
||
fn call(&mut self, mut req: hyper::Request<hyper::Body>) -> Self::Future { | ||
req.extensions_mut() | ||
.insert(Claim::new("test".to_string(), self.scopes.clone())); | ||
self.inner.call(req) | ||
} | ||
} |
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