Skip to content

Commit

Permalink
backout changes to property bag
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Dec 7, 2022
1 parent 7f61c5c commit 768de69
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
28 changes: 14 additions & 14 deletions aws/rust-runtime/aws-endpoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,62 +84,62 @@ impl ResolveEndpoint<Params> for EndpointShim {
}
}

/// Middleware Stage to convert a smithy into signing information
/// Middleware Stage to add authentication information from a Smithy endpoint into the property bag
///
/// AwsEndpointStage implements [`MapRequest`](aws_smithy_http::middleware::MapRequest). It will:
/// AwsAuthStage implements [`MapRequest`](MapRequest). It will:
/// 1. Load an endpoint from the property bag
/// 2. Set the `SigningRegion` and `SigningService` in the property bag to drive downstream
/// signing middleware.
#[derive(Clone, Debug)]
pub struct AwsAuthStage;

#[derive(Debug)]
enum AwsEndpointStageErrorKind {
enum AwsAuthStageErrorKind {
NoEndpointResolver,
EndpointResolutionError(BoxError),
}

#[derive(Debug)]
pub struct AwsEndpointStageError {
kind: AwsEndpointStageErrorKind,
pub struct AwsAuthStageError {
kind: AwsAuthStageErrorKind,
}

impl fmt::Display for AwsEndpointStageError {
impl fmt::Display for AwsAuthStageError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use AwsEndpointStageErrorKind::*;
use AwsAuthStageErrorKind::*;
match &self.kind {
NoEndpointResolver => write!(f, "endpoint resolution failed: no endpoint present"),
EndpointResolutionError(_) => write!(f, "endpoint resolution failed"),
}
}
}

impl Error for AwsEndpointStageError {
impl Error for AwsAuthStageError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
use AwsEndpointStageErrorKind::*;
use AwsAuthStageErrorKind::*;
match &self.kind {
EndpointResolutionError(source) => Some(source.as_ref() as _),
NoEndpointResolver => None,
}
}
}

impl From<AwsEndpointStageErrorKind> for AwsEndpointStageError {
fn from(kind: AwsEndpointStageErrorKind) -> Self {
impl From<AwsAuthStageErrorKind> for AwsAuthStageError {
fn from(kind: AwsAuthStageErrorKind) -> Self {
Self { kind }
}
}

impl MapRequest for AwsAuthStage {
type Error = AwsEndpointStageError;
type Error = AwsAuthStageError;

fn apply(&self, request: Request) -> Result<Request, Self::Error> {
request.augment(|http_req, props| {
let endpoint = props
.get::<aws_smithy_types::endpoint::Endpoint>()
.ok_or(AwsEndpointStageErrorKind::NoEndpointResolver)?;
.ok_or(AwsAuthStageErrorKind::NoEndpointResolver)?;
let (signing_scope_override, signing_service_override) = smithy_to_aws(endpoint)
.map_err(|err| AwsEndpointStageErrorKind::EndpointResolutionError(err))?;
.map_err(|err| AwsAuthStageErrorKind::EndpointResolutionError(err))?;

if let Some(signing_scope) = signing_scope_override {
props.insert(signing_scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ class EndpointsDecorator : RustCodegenDecorator<ClientProtocolGenerator, ClientC
"""
let endpoint_params = #{Params}::builder()#{builderFields:W}.build()
.map_err(#{BuildError}::other)?;
let endpoint_result = ${section.config}.endpoint_resolver.resolve_endpoint(&endpoint_params)
.map_err(#{BuildError}::other);
let endpoint_result = ${section.config}.endpoint_resolver.resolve_endpoint(&endpoint_params);
""",
"builderFields" to builderFields(typesGenerator.params, section),
*codegenScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ class EndpointsDecoratorTest {
.bucket("bucket-name").build().expect("input is valid")
.make_operation(&conf).await.expect("valid operation");
use $moduleName::endpoint::{Params};
use aws_smithy_types::endpoint::Endpoint;
use aws_smithy_http::endpoint::Result;
let props = operation.properties();
let endpoint_params = props.get::<Params>().unwrap();
let endpoint = props.get::<Endpoint>().unwrap();
let endpoint_params = props.get::<Params>().expect("endpoint params in the bag");
let endpoint_result = props.get::<Result>().expect("endpoint result in the bag");
let endpoint = endpoint_result.as_ref().expect("endpoint resolved properly");
assert_eq!(
endpoint_params,
&Params::builder()
Expand Down
2 changes: 1 addition & 1 deletion design/src/rfcs/rfc0014_timeout_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<S> tower::Layer<S> for AwsMiddleware {
fn layer(&self, inner: S) -> Self::Service {
let credential_provider = AsyncMapRequestLayer::for_mapper(CredentialsStage::new());
let signer = MapRequestLayer::for_mapper(SigV4SigningStage::new(SigV4Signer::new()));
let endpoint_resolver = MapRequestLayer::for_mapper(AwsEndpointStage);
let endpoint_resolver = MapRequestLayer::for_mapper(AwsAuthStage);
let user_agent = MapRequestLayer::for_mapper(UserAgentStage::new());
ServiceBuilder::new()
.layer(endpoint_resolver)
Expand Down
18 changes: 9 additions & 9 deletions rust-runtime/aws-smithy-http/src/endpoint/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

use std::error::{Error as StdError, Error};
use std::error::Error;
use std::fmt;

/// Endpoint resolution failed
Expand Down Expand Up @@ -42,8 +42,8 @@ impl fmt::Display for ResolveEndpointError {
}
}

impl StdError for ResolveEndpointError {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
impl Error for ResolveEndpointError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
self.source.as_ref().map(|err| err.as_ref() as _)
}
}
Expand All @@ -52,10 +52,10 @@ impl StdError for ResolveEndpointError {
pub(super) enum InvalidEndpointErrorKind {
EndpointMustHaveScheme,
FailedToConstructAuthority {
source: Box<dyn StdError + Send + Sync + 'static>,
source: Box<dyn Error + Send + Sync + 'static>,
},
FailedToConstructUri {
source: Box<dyn StdError + Send + Sync + 'static>,
source: Box<dyn Error + Send + Sync + 'static>,
},
}

Expand All @@ -72,7 +72,7 @@ impl InvalidEndpointError {
}

pub(super) fn failed_to_construct_authority(
source: impl Into<Box<dyn StdError + Send + Sync + 'static>>,
source: impl Into<Box<dyn Error + Send + Sync + 'static>>,
) -> Self {
Self {
kind: InvalidEndpointErrorKind::FailedToConstructAuthority {
Expand All @@ -82,7 +82,7 @@ impl InvalidEndpointError {
}

pub(super) fn failed_to_construct_uri(
source: impl Into<Box<dyn StdError + Send + Sync + 'static>>,
source: impl Into<Box<dyn Error + Send + Sync + 'static>>,
) -> Self {
Self {
kind: InvalidEndpointErrorKind::FailedToConstructUri {
Expand Down Expand Up @@ -112,8 +112,8 @@ impl fmt::Display for InvalidEndpointError {
}
}

impl StdError for InvalidEndpointError {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
impl Error for InvalidEndpointError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
use InvalidEndpointErrorKind as ErrorKind;
match &self.kind {
ErrorKind::FailedToConstructUri { source }
Expand Down

0 comments on commit 768de69

Please sign in to comment.