-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add: tests to ensure all interceptors are run if an error occurs in one #2664
Changes from 9 commits
3ac9c1e
5725d56
c5b76ee
3d545d5
12bc394
9c5f1e3
7014da4
c135c68
fb83922
8e3f6aa
e4690ee
21e27dc
07dc309
80d59cb
fe3026e
3c56aa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,17 +48,17 @@ impl AuthOptionResolverParams { | |
} | ||
|
||
pub trait AuthOptionResolver: Send + Sync + fmt::Debug { | ||
fn resolve_auth_options<'a>( | ||
&'a self, | ||
fn resolve_auth_options( | ||
&self, | ||
params: &AuthOptionResolverParams, | ||
) -> Result<Cow<'a, [AuthSchemeId]>, BoxError>; | ||
) -> Result<Cow<'_, [AuthSchemeId]>, BoxError>; | ||
} | ||
|
||
impl AuthOptionResolver for Box<dyn AuthOptionResolver> { | ||
fn resolve_auth_options<'a>( | ||
&'a self, | ||
fn resolve_auth_options( | ||
&self, | ||
params: &AuthOptionResolverParams, | ||
) -> Result<Cow<'a, [AuthSchemeId]>, BoxError> { | ||
Comment on lines
-51
to
-61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The linter was complaining about an unnecessary explicit lifetime here and in the auth option resolver so I switched it to an anonymous lifetime. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. I take it to mean that the compiler deterministically derives the anomalous lifeitme in this case from the first There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's what happens AFAICT |
||
) -> Result<Cow<'_, [AuthSchemeId]>, BoxError> { | ||
(**self).resolve_auth_options(params) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ use std::time::SystemTime; | |
#[cfg(feature = "http-auth")] | ||
pub mod http; | ||
|
||
#[cfg(feature = "anonymous-auth")] | ||
pub mod anonymous; | ||
|
||
pub trait IdentityResolver: Send + Sync + Debug { | ||
fn resolve_identity(&self, config_bag: &ConfigBag) -> Future<Identity>; | ||
} | ||
|
@@ -65,30 +68,6 @@ impl Identity { | |
} | ||
} | ||
|
||
#[derive(Debug)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||
pub struct AnonymousIdentity; | ||
|
||
impl AnonymousIdentity { | ||
pub fn new() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct AnonymousIdentityResolver; | ||
|
||
impl AnonymousIdentityResolver { | ||
pub fn new() -> Self { | ||
AnonymousIdentityResolver | ||
} | ||
} | ||
|
||
impl IdentityResolver for AnonymousIdentityResolver { | ||
fn resolve_identity(&self, _: &ConfigBag) -> Future<Identity> { | ||
Future::ready(Ok(Identity::new(AnonymousIdentity::new(), None))) | ||
} | ||
} | ||
|
||
pub mod builders { | ||
use super::*; | ||
use crate::client::auth::AuthSchemeId; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use crate::client::identity::{Identity, IdentityResolver}; | ||
use crate::client::orchestrator::Future; | ||
use crate::config_bag::ConfigBag; | ||
|
||
#[derive(Debug)] | ||
pub struct AnonymousIdentity; | ||
|
||
impl AnonymousIdentity { | ||
pub fn new() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct AnonymousIdentityResolver; | ||
|
||
impl AnonymousIdentityResolver { | ||
pub fn new() -> Self { | ||
AnonymousIdentityResolver | ||
} | ||
} | ||
|
||
impl IdentityResolver for AnonymousIdentityResolver { | ||
fn resolve_identity(&self, _: &ConfigBag) -> Future<Identity> { | ||
Future::ready(Ok(Identity::new(AnonymousIdentity::new(), None))) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//! The [AnonymousAuthRuntimePlugin] and supporting code. | ||
|
||
use super::RuntimePlugin; | ||
use crate::client::auth::option_resolver::{ | ||
StaticAuthOptionResolver, StaticAuthOptionResolverParams, | ||
}; | ||
use crate::client::auth::{AuthSchemeId, HttpAuthScheme, HttpAuthSchemes, HttpRequestSigner}; | ||
use crate::client::identity::anonymous::AnonymousIdentityResolver; | ||
use crate::client::identity::{Identity, IdentityResolver, IdentityResolvers}; | ||
use crate::client::interceptors::Interceptors; | ||
use crate::client::orchestrator::{ConfigBagAccessors, HttpRequest}; | ||
use crate::client::runtime_plugin::BoxError; | ||
use crate::config_bag::ConfigBag; | ||
|
||
const ANONYMOUS_AUTH_SCHEME_ID: AuthSchemeId = AuthSchemeId::new("anonymous"); | ||
|
||
/// A [RuntimePlugin] to provide anonymous authentication. This runtime plugin sets its own: | ||
/// - [AuthOptionResolver] | ||
/// - [AuthOptionResolverParams] | ||
/// - [IdentityResolvers] | ||
/// - [HttpAuthSchemes] | ||
/// | ||
/// **The above components will replace any existing ones!** As such, don't use this plugin unless: | ||
/// - You only need to make anonymous requests, such as when interacting with [Open Data](https://aws.amazon.com/opendata/). | ||
/// - You're writing orchestrator tests and don't care about authentication. | ||
pub struct AnonymousAuthRuntimePlugin; | ||
Velfi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
impl RuntimePlugin for AnonymousAuthRuntimePlugin { | ||
fn configure( | ||
&self, | ||
cfg: &mut ConfigBag, | ||
_interceptors: &mut Interceptors, | ||
) -> Result<(), BoxError> { | ||
cfg.set_auth_option_resolver_params(StaticAuthOptionResolverParams::new().into()); | ||
cfg.set_auth_option_resolver(StaticAuthOptionResolver::new(vec![ | ||
ANONYMOUS_AUTH_SCHEME_ID, | ||
])); | ||
cfg.set_identity_resolvers( | ||
IdentityResolvers::builder() | ||
.identity_resolver(ANONYMOUS_AUTH_SCHEME_ID, AnonymousIdentityResolver::new()) | ||
.build(), | ||
); | ||
cfg.set_http_auth_schemes( | ||
HttpAuthSchemes::builder() | ||
.auth_scheme(ANONYMOUS_AUTH_SCHEME_ID, AnonymousAuthScheme::new()) | ||
.build(), | ||
); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
pub struct AnonymousAuthScheme { | ||
signer: AnonymousSigner, | ||
} | ||
|
||
impl AnonymousAuthScheme { | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
struct AnonymousSigner; | ||
|
||
impl HttpRequestSigner for AnonymousSigner { | ||
fn sign_request( | ||
&self, | ||
_request: &mut HttpRequest, | ||
_identity: &Identity, | ||
_config_bag: &ConfigBag, | ||
) -> Result<(), BoxError> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl HttpAuthScheme for AnonymousAuthScheme { | ||
fn scheme_id(&self) -> AuthSchemeId { | ||
ANONYMOUS_AUTH_SCHEME_ID | ||
} | ||
|
||
fn identity_resolver<'a>( | ||
&self, | ||
identity_resolvers: &'a IdentityResolvers, | ||
) -> Option<&'a dyn IdentityResolver> { | ||
identity_resolvers.identity_resolver(ANONYMOUS_AUTH_SCHEME_ID) | ||
} | ||
|
||
fn request_signer(&self) -> &dyn HttpRequestSigner { | ||
&self.signer | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the anonymous auth stuff was always available. I added some more stuff related to anonymous auth and feature-gated it since we were already doing so for
http-auth
.