Skip to content

Commit

Permalink
Merge commit 'e1cf72e52d152519f57a66d95a23322fe1de0759' into RFC30/Blob
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-k-cameron committed May 3, 2023
2 parents c209b13 + e1cf72e commit 6f220f4
Show file tree
Hide file tree
Showing 69 changed files with 1,663 additions and 1,040 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ author = "rcoh"
references = ["smithy-rs#2612"]
meta = { "breaking" = false, "tada" = false, "bug" = false }


[[smithy-rs]]
message = "Implement `Ord` and `PartialOrd` for `DateTime`."
author = "henriiik"
references = ["smithy-rs#2653"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
34 changes: 15 additions & 19 deletions aws/rust-runtime/aws-runtime/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ pub mod sigv4 {
SignableRequest, SignatureLocation, SigningParams, SigningSettings,
UriPathNormalizationMode,
};
use aws_smithy_http::property_bag::PropertyBag;
use aws_smithy_runtime_api::client::auth::{AuthSchemeId, HttpAuthScheme, HttpRequestSigner};
use aws_smithy_runtime_api::client::identity::{Identity, IdentityResolver, IdentityResolvers};
use aws_smithy_runtime_api::client::orchestrator::{
BoxError, HttpAuthScheme, HttpRequest, HttpRequestSigner,
};
use aws_smithy_runtime_api::client::orchestrator::{BoxError, ConfigBagAccessors, HttpRequest};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_types::region::SigningRegion;
use aws_types::SigningService;
use std::time::{Duration, SystemTime};
Expand All @@ -24,7 +23,7 @@ pub mod sigv4 {
`expires_in` duration because the credentials used to sign it will expire first.";

/// Auth scheme ID for SigV4.
pub const SCHEME_ID: &str = "sigv4";
pub const SCHEME_ID: AuthSchemeId = AuthSchemeId::new("sigv4");

/// SigV4 auth scheme.
#[derive(Debug, Default)]
Expand All @@ -40,7 +39,7 @@ pub mod sigv4 {
}

impl HttpAuthScheme for SigV4HttpAuthScheme {
fn scheme_id(&self) -> &'static str {
fn scheme_id(&self) -> AuthSchemeId {
SCHEME_ID
}

Expand Down Expand Up @@ -88,8 +87,6 @@ pub mod sigv4 {
pub signing_optional: bool,
/// Optional expiration (for presigning)
pub expires_in: Option<Duration>,
/// Timestamp to sign with.
pub request_timestamp: SystemTime,
}

impl Default for SigningOptions {
Expand All @@ -103,7 +100,6 @@ pub mod sigv4 {
signature_type: HttpSignatureType::HttpRequestHeaders,
signing_optional: false,
expires_in: None,
request_timestamp: SystemTime::now(),
}
}
}
Expand Down Expand Up @@ -168,11 +164,11 @@ pub mod sigv4 {
settings: SigningSettings,
credentials: &'a Credentials,
operation_config: &'a SigV4OperationSigningConfig,
request_timestamp: SystemTime,
) -> SigningParams<'a> {
if let Some(expires_in) = settings.expires_in {
if let Some(creds_expires_time) = credentials.expiry() {
let presigned_expires_time =
operation_config.signing_options.request_timestamp + expires_in;
let presigned_expires_time = request_timestamp + expires_in;
if presigned_expires_time > creds_expires_time {
tracing::warn!(EXPIRATION_WARNING);
}
Expand All @@ -184,7 +180,7 @@ pub mod sigv4 {
.secret_key(credentials.secret_access_key())
.region(operation_config.region.as_ref())
.service_name(operation_config.service.as_ref())
.time(operation_config.signing_options.request_timestamp)
.time(request_timestamp)
.settings(settings);
builder.set_security_token(credentials.session_token());
builder.build().expect("all required fields set")
Expand All @@ -196,12 +192,12 @@ pub mod sigv4 {
&self,
request: &mut HttpRequest,
identity: &Identity,
// TODO(enableNewSmithyRuntime): should this be the config bag?
signing_properties: &PropertyBag,
config_bag: &ConfigBag,
) -> Result<(), BoxError> {
let operation_config = signing_properties
let operation_config = config_bag
.get::<SigV4OperationSigningConfig>()
.ok_or("missing operation signing config for SigV4")?;
let request_time = config_bag.request_time().unwrap_or_default().system_time();

let credentials = if let Some(creds) = identity.data::<Credentials>() {
creds
Expand All @@ -213,7 +209,8 @@ pub mod sigv4 {
};

let settings = Self::settings(operation_config);
let signing_params = Self::signing_params(settings, credentials, operation_config);
let signing_params =
Self::signing_params(settings, credentials, operation_config, request_time);

let (signing_instructions, _signature) = {
// A body that is already in memory can be signed directly. A body that is not in memory
Expand Down Expand Up @@ -283,17 +280,16 @@ pub mod sigv4 {
signature_type: HttpSignatureType::HttpRequestHeaders,
signing_optional: false,
expires_in: None,
request_timestamp: now,
payload_override: None,
},
};
SigV4HttpRequestSigner::signing_params(settings, &credentials, &operation_config);
SigV4HttpRequestSigner::signing_params(settings, &credentials, &operation_config, now);
assert!(!logs_contain(EXPIRATION_WARNING));

let mut settings = SigningSettings::default();
settings.expires_in = Some(creds_expire_in + Duration::from_secs(10));

SigV4HttpRequestSigner::signing_params(settings, &credentials, &operation_config);
SigV4HttpRequestSigner::signing_params(settings, &credentials, &operation_config, now);
assert!(logs_contain(EXPIRATION_WARNING));
}
}
Expand Down
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-runtime/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
/// Credentials-based identity support.
pub mod credentials {
use aws_credential_types::cache::SharedCredentialsCache;
use aws_smithy_http::property_bag::PropertyBag;
use aws_smithy_runtime_api::client::identity::{Identity, IdentityResolver};
use aws_smithy_runtime_api::client::orchestrator::{BoxError, Future};
use aws_smithy_runtime_api::config_bag::ConfigBag;

/// Smithy identity resolver for AWS credentials.
#[derive(Debug)]
Expand All @@ -24,7 +24,7 @@ pub mod credentials {
}

impl IdentityResolver for CredentialsIdentityResolver {
fn resolve_identity(&self, _identity_properties: &PropertyBag) -> Future<Identity> {
fn resolve_identity(&self, _config_bag: &ConfigBag) -> Future<Identity> {
let cache = self.credentials_cache.clone();
Future::new(Box::pin(async move {
let credentials = cache.as_ref().provide_cached_credentials().await?;
Expand Down
11 changes: 3 additions & 8 deletions aws/rust-runtime/aws-runtime/src/invocation_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use aws_smithy_runtime_api::client::interceptors::error::BoxError;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::orchestrator::{HttpRequest, HttpResponse};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use http::{HeaderName, HeaderValue};
use uuid::Uuid;
Expand Down Expand Up @@ -35,10 +34,10 @@ impl Default for InvocationIdInterceptor {
}
}

impl Interceptor<HttpRequest, HttpResponse> for InvocationIdInterceptor {
impl Interceptor for InvocationIdInterceptor {
fn modify_before_retry_loop(
&self,
context: &mut InterceptorContext<HttpRequest, HttpResponse>,
context: &mut InterceptorContext,
_cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
let headers = context.request_mut()?.headers_mut();
Expand Down Expand Up @@ -74,15 +73,11 @@ mod tests {
use crate::invocation_id::InvocationIdInterceptor;
use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::orchestrator::{HttpRequest, HttpResponse};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_runtime_api::type_erasure::TypedBox;
use http::HeaderValue;

fn expect_header<'a>(
context: &'a InterceptorContext<HttpRequest, HttpResponse>,
header_name: &str,
) -> &'a HeaderValue {
fn expect_header<'a>(context: &'a InterceptorContext, header_name: &str) -> &'a HeaderValue {
context
.request()
.unwrap()
Expand Down
5 changes: 2 additions & 3 deletions aws/rust-runtime/aws-runtime/src/recursion_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

use aws_smithy_runtime_api::client::interceptors::{BoxError, Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::orchestrator::{HttpRequest, HttpResponse};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_types::os_shim_internal::Env;
use http::HeaderValue;
Expand Down Expand Up @@ -37,10 +36,10 @@ impl RecursionDetectionInterceptor {
}
}

impl Interceptor<HttpRequest, HttpResponse> for RecursionDetectionInterceptor {
impl Interceptor for RecursionDetectionInterceptor {
fn modify_before_signing(
&self,
context: &mut InterceptorContext<HttpRequest, HttpResponse>,
context: &mut InterceptorContext,
_cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
let request = context.request_mut()?;
Expand Down
10 changes: 3 additions & 7 deletions aws/rust-runtime/aws-runtime/src/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use aws_http::user_agent::{ApiMetadata, AwsUserAgent};
use aws_smithy_runtime_api::client::interceptors::error::BoxError;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::orchestrator::{HttpRequest, HttpResponse};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_types::app_name::AppName;
use aws_types::os_shim_internal::Env;
Expand Down Expand Up @@ -70,10 +69,10 @@ fn header_values(
))
}

impl Interceptor<HttpRequest, HttpResponse> for UserAgentInterceptor {
impl Interceptor for UserAgentInterceptor {
fn modify_before_signing(
&self,
context: &mut InterceptorContext<HttpRequest, HttpResponse>,
context: &mut InterceptorContext,
cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
let api_metadata = cfg
Expand Down Expand Up @@ -113,10 +112,7 @@ mod tests {
use aws_smithy_runtime_api::type_erasure::TypedBox;
use aws_smithy_types::error::display::DisplayErrorContext;

fn expect_header<'a>(
context: &'a InterceptorContext<HttpRequest, HttpResponse>,
header_name: &str,
) -> &'a str {
fn expect_header<'a>(context: &'a InterceptorContext, header_name: &str) -> &'a str {
context
.request()
.unwrap()
Expand Down
2 changes: 0 additions & 2 deletions aws/sdk-adhoc-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ val allCodegenTests = listOf(
,
"codegen": {
"includeFluentClient": false,
"enableNewCrateOrganizationScheme": true
},
"customizationConfig": {
"awsSdk": {
Expand All @@ -63,7 +62,6 @@ val allCodegenTests = listOf(
,
"codegen": {
"includeFluentClient": false,
"enableNewCrateOrganizationScheme": true
},
"customizationConfig": {
"awsSdk": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CredentialsProviderDecorator : ClientCodegenDecorator {
codegenContext: ClientCodegenContext,
baseCustomizations: List<ServiceRuntimePluginCustomization>,
): List<ServiceRuntimePluginCustomization> =
baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) {
baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) {
it + listOf(CredentialsIdentityResolverRegistration(codegenContext))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class HttpConnectorDecorator : ClientCodegenDecorator {
codegenContext: ClientCodegenContext,
baseCustomizations: List<ConfigCustomization>,
): List<ConfigCustomization> =
baseCustomizations.letIf(!codegenContext.settings.codegenConfig.enableNewSmithyRuntime) {
baseCustomizations.letIf(codegenContext.smithyRuntimeMode.exclusivelyGenerateMiddleware) {
it + HttpConnectorConfigCustomization(codegenContext)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HttpRequestChecksumDecorator : ClientCodegenDecorator {

// TODO(enableNewSmithyRuntime): Implement checksumming via interceptor and delete this decorator
private fun applies(codegenContext: ClientCodegenContext): Boolean =
!codegenContext.settings.codegenConfig.enableNewSmithyRuntime
codegenContext.smithyRuntimeMode.exclusivelyGenerateMiddleware

override fun operationCustomizations(
codegenContext: ClientCodegenContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class HttpResponseChecksumDecorator : ClientCodegenDecorator {

// TODO(enableNewSmithyRuntime): Implement checksumming via interceptor and delete this decorator
private fun applies(codegenContext: ClientCodegenContext, operationShape: OperationShape): Boolean =
!codegenContext.settings.codegenConfig.enableNewSmithyRuntime && operationShape.outputShape != ShapeId.from("com.amazonaws.s3#GetObjectOutput")
codegenContext.smithyRuntimeMode.generateMiddleware && operationShape.outputShape != ShapeId.from("com.amazonaws.s3#GetObjectOutput")

override fun operationCustomizations(
codegenContext: ClientCodegenContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class S3TestDependencies(private val codegenContext: ClientCodegenContext) : Lib

// TODO(enableNewSmithyRuntime): These additional dependencies may not be needed anymore when removing this flag
// depending on if the sra-test is kept around or not.
if (codegenContext.settings.codegenConfig.enableNewSmithyRuntime) {
if (codegenContext.smithyRuntimeMode.generateOrchestrator) {
addDependency(CargoDependency.smithyRuntime(codegenContext.runtimeConfig).toDevDependency())
addDependency(CargoDependency.smithyRuntimeApi(codegenContext.runtimeConfig).toDevDependency())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InvocationIdDecorator : ClientCodegenDecorator {
codegenContext: ClientCodegenContext,
baseCustomizations: List<ServiceRuntimePluginCustomization>,
): List<ServiceRuntimePluginCustomization> =
baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) {
baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) {
it + listOf(InvocationIdRuntimePluginCustomization(codegenContext))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RecursionDetectionDecorator : ClientCodegenDecorator {
codegenContext: ClientCodegenContext,
baseCustomizations: List<ServiceRuntimePluginCustomization>,
): List<ServiceRuntimePluginCustomization> =
baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) {
baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) {
it + listOf(RecursionDetectionRuntimePluginCustomization(codegenContext))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SigV4AuthDecorator : ClientCodegenDecorator {
codegenContext: ClientCodegenContext,
baseCustomizations: List<ServiceRuntimePluginCustomization>,
): List<ServiceRuntimePluginCustomization> =
baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) {
baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) {
it + listOf(AuthServiceRuntimePluginCustomization(codegenContext))
}

Expand All @@ -42,7 +42,7 @@ class SigV4AuthDecorator : ClientCodegenDecorator {
operation: OperationShape,
baseCustomizations: List<OperationRuntimePluginCustomization>,
): List<OperationRuntimePluginCustomization> =
baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) {
baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) {
it + listOf(AuthOperationRuntimePluginCustomization(codegenContext))
}
}
Expand Down Expand Up @@ -102,10 +102,8 @@ private class AuthOperationRuntimePluginCustomization(private val codegenContext
val runtimeApi = RuntimeType.smithyRuntimeApi(runtimeConfig)
val awsRuntime = AwsRuntimeType.awsRuntime(runtimeConfig)
arrayOf(
"AuthOptionListResolver" to runtimeApi.resolve("client::auth::option_resolver::AuthOptionListResolver"),
"HttpAuthOption" to runtimeApi.resolve("client::orchestrator::HttpAuthOption"),
"StaticAuthOptionResolver" to runtimeApi.resolve("client::auth::option_resolver::StaticAuthOptionResolver"),
"HttpSignatureType" to awsRuntime.resolve("auth::sigv4::HttpSignatureType"),
"PropertyBag" to RuntimeType.smithyHttp(runtimeConfig).resolve("property_bag::PropertyBag"),
"SIGV4_SCHEME_ID" to awsRuntime.resolve("auth::sigv4::SCHEME_ID"),
"SigV4OperationSigningConfig" to awsRuntime.resolve("auth::sigv4::SigV4OperationSigningConfig"),
"SigningOptions" to awsRuntime.resolve("auth::sigv4::SigningOptions"),
Expand Down Expand Up @@ -136,16 +134,15 @@ private class AuthOperationRuntimePluginCustomization(private val codegenContext
signing_options.normalize_uri_path = $normalizeUrlPath;
signing_options.signing_optional = $signingOptional;
signing_options.payload_override = #{payload_override};
signing_options.request_timestamp = cfg.request_time().unwrap_or_default().system_time();
let mut sigv4_properties = #{PropertyBag}::new();
sigv4_properties.insert(#{SigV4OperationSigningConfig} {
${section.configBagName}.put(#{SigV4OperationSigningConfig} {
region: signing_region,
service: signing_service,
signing_options,
});
let auth_option_resolver = #{AuthOptionListResolver}::new(
vec![#{HttpAuthOption}::new(#{SIGV4_SCHEME_ID}, std::sync::Arc::new(sigv4_properties))]
// TODO(enableNewSmithyRuntime): Make auth options additive in the config bag so that multiple codegen decorators can register them
let auth_option_resolver = #{StaticAuthOptionResolver}::new(
vec![#{SIGV4_SCHEME_ID}]
);
${section.configBagName}.set_auth_option_resolver(auth_option_resolver);
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class UserAgentDecorator : ClientCodegenDecorator {
codegenContext: ClientCodegenContext,
baseCustomizations: List<ServiceRuntimePluginCustomization>,
): List<ServiceRuntimePluginCustomization> =
baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) {
baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) {
it + listOf(AddApiMetadataIntoConfigBag(codegenContext))
}

Expand Down
3 changes: 1 addition & 2 deletions aws/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ fun generateSmithyBuild(services: AwsServices): String {
"renameErrors": false,
"debugMode": $debugMode,
"eventStreamAllowList": [$eventStreamAllowListMembers],
"enableNewCrateOrganizationScheme": true,
"enableNewSmithyRuntime": false
"enableNewSmithyRuntime": "middleware"
},
"service": "${service.service}",
"module": "$moduleName",
Expand Down
Loading

0 comments on commit 6f220f4

Please sign in to comment.