Skip to content

Commit

Permalink
Rename signing_service to signing_name (#2911)
Browse files Browse the repository at this point in the history
Part of the SigV4a update. I split this out to making review simpler.

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
Velfi authored Aug 17, 2023
1 parent 2d61502 commit 200fb61
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 178 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ author = "jdisanti"
[[smithy-rs]]
message = "`RuntimeComponents` and `RuntimeComponentsBuilder` are now re-exported in generated clients so that implementing a custom interceptor or runtime plugin doens't require directly depending on `aws-smithy-runtime-api`."
references = ["smithy-rs#2904"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client"}
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"

[[smithy-rs]]
Expand All @@ -45,3 +45,9 @@ message = """Several breaking changes were made to the aws-sigv4 API to remove t
references = ["smithy-rs#2921"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "rcoh"

[[aws-sdk-rust]]
message = "In sigV4-related code, rename 'signing service' to 'signing name'. This aligns with the terminology used by the endpoint resolver."
references = ["smithy-rs#2911"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "Velfi"
36 changes: 18 additions & 18 deletions aws/rust-runtime/aws-endpoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use aws_smithy_types::endpoint::Endpoint as SmithyEndpoint;
use aws_smithy_types::Document;

use aws_types::region::{Region, SigningRegion};
use aws_types::SigningService;
use aws_types::SigningName;

/// Middleware Stage to add authentication information from a Smithy endpoint into the property bag
///
/// 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
/// 2. Set the `SigningRegion` and `SigningName` in the property bag to drive downstream
/// signing middleware.
#[derive(Clone, Debug)]
pub struct AwsAuthStage;
Expand Down Expand Up @@ -74,21 +74,21 @@ impl MapRequest for AwsAuthStage {
let endpoint = props
.get::<aws_smithy_types::endpoint::Endpoint>()
.ok_or(AwsAuthStageErrorKind::NoEndpointResolver)?;
let (signing_scope_override, signing_service_override) = smithy_to_aws(endpoint)
let (signing_region_override, signing_name_override) = smithy_to_aws(endpoint)
.map_err(|err| AwsAuthStageErrorKind::EndpointResolutionError(err))?;

if let Some(signing_scope) = signing_scope_override {
props.insert(signing_scope);
if let Some(signing_region) = signing_region_override {
props.insert(signing_region);
}
if let Some(signing_service) = signing_service_override {
props.insert(signing_service);
if let Some(signing_name) = signing_name_override {
props.insert(signing_name);
}
Ok(http_req)
})
}
}

type EndpointMetadata = (Option<SigningRegion>, Option<SigningService>);
type EndpointMetadata = (Option<SigningRegion>, Option<SigningName>);

fn smithy_to_aws(value: &SmithyEndpoint) -> Result<EndpointMetadata, Box<dyn Error + Send + Sync>> {
// look for v4 as an auth scheme
Expand Down Expand Up @@ -127,12 +127,12 @@ fn smithy_to_aws(value: &SmithyEndpoint) -> Result<EndpointMetadata, Box<dyn Err
None => None,
_ => return Err("unexpected type".into()),
};
let signing_service = match v4.get("signingName") {
Some(Document::String(s)) => Some(SigningService::from(s.to_string())),
let signing_name = match v4.get("signingName") {
Some(Document::String(s)) => Some(SigningName::from(s.to_string())),
None => None,
_ => return Err("unexpected type".into()),
};
Ok((signing_scope, signing_service))
Ok((signing_scope, signing_name))
}

#[cfg(test)]
Expand All @@ -147,7 +147,7 @@ mod test {
use http::header::HOST;

use aws_types::region::{Region, SigningRegion};
use aws_types::SigningService;
use aws_types::SigningName;

use crate::AwsAuthStage;

Expand All @@ -162,14 +162,14 @@ mod test {
{
let mut props = req.properties_mut();
props.insert(SigningRegion::from(region.clone()));
props.insert(SigningService::from_static("kinesis"));
props.insert(SigningName::from_static("kinesis"));
props.insert(endpoint);
};
let req = AwsAuthStage.apply(req).expect("should succeed");
assert_eq!(req.properties().get(), Some(&SigningRegion::from(region)));
assert_eq!(
req.properties().get(),
Some(&SigningService::from_static("kinesis"))
Some(&SigningName::from_static("kinesis"))
);

assert!(req.http().headers().get(HOST).is_none());
Expand Down Expand Up @@ -206,7 +206,7 @@ mod test {
{
let mut props = req.properties_mut();
props.insert(region);
props.insert(SigningService::from_static("qldb"));
props.insert(SigningName::from_static("qldb"));
props.insert(endpoint);
};
let req = AwsAuthStage.apply(req).expect("should succeed");
Expand All @@ -216,7 +216,7 @@ mod test {
);
assert_eq!(
req.properties().get(),
Some(&SigningService::from_static("qldb-override"))
Some(&SigningName::from_static("qldb-override"))
);
}

Expand All @@ -229,14 +229,14 @@ mod test {
{
let mut props = req.properties_mut();
props.insert(region.clone());
props.insert(SigningService::from_static("qldb"));
props.insert(SigningName::from_static("qldb"));
props.insert(endpoint);
};
let req = AwsAuthStage.apply(req).expect("should succeed");
assert_eq!(req.properties().get(), Some(&region));
assert_eq!(
req.properties().get(),
Some(&SigningService::from_static("qldb"))
Some(&SigningName::from_static("qldb"))
);
}
}
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-inlineable/tests/middleware_e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use aws_inlineable::middleware::DefaultMiddleware;
use aws_sig_auth::signer::OperationSigningConfig;
use aws_smithy_async::time::SharedTimeSource;
use aws_types::region::SigningRegion;
use aws_types::SigningService;
use aws_types::SigningName;

type Client<C> = aws_smithy_client::Client<C, DefaultMiddleware>;

Expand Down Expand Up @@ -94,7 +94,7 @@ fn test_operation() -> Operation<TestOperationParser, AwsResponseRetryClassifier
);
conf.insert(SigningRegion::from_static("test-region"));
conf.insert(OperationSigningConfig::default_config());
conf.insert(SigningService::from_static("test-service-signing"));
conf.insert(SigningName::from_static("test-service-signing"));
conf.insert(SharedTimeSource::new(
UNIX_EPOCH + Duration::from_secs(1613414417),
));
Expand Down
Loading

0 comments on commit 200fb61

Please sign in to comment.