Skip to content
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

Make service config just contain a FrozenLayer in the orchestrator mode #2762

Merged
merged 19 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
189f2b5
Make types storable in config layer
ysaito1001 Jun 10, 2023
9867d48
Make service config contain just `FrozenLayer`
ysaito1001 Jun 12, 2023
3b1b71a
Update tests to work with layer-backed service config
ysaito1001 Jun 12, 2023
794f063
Use inlineable in test other than `IdempotencyToken`
ysaito1001 Jun 12, 2023
a69a278
Merge branch 'main' into ysaito/frozen-layer-backed-service-config
ysaito1001 Jun 12, 2023
f98f99d
Update codegen-client/src/test/kotlin/software/amazon/smithy/rust/cod…
ysaito1001 Jun 13, 2023
3471a62
Merge branch 'main' into ysaito/frozen-layer-backed-service-config
ysaito1001 Jun 13, 2023
7333e70
Remove unnecessary bifurcation for accessing time_source
ysaito1001 Jun 13, 2023
b988ad9
Leave identity_resolvers and interceptors as fields
ysaito1001 Jun 14, 2023
52a0d6e
Avoid unsetting fields during the `build` method
ysaito1001 Jun 14, 2023
f7b96ad
Update externl-types.toml based on the latest main
ysaito1001 Jun 14, 2023
303c90a
Fix redundant-clone clippy warning
ysaito1001 Jun 14, 2023
2461a7f
Merge branch 'main' into ysaito/frozen-layer-backed-service-config
Velfi Jun 14, 2023
7b9b56a
Update service config and builder in `ApiKeyAuthDecorator`
ysaito1001 Jun 15, 2023
89185fa
Update `make_token` to `token_provider`
ysaito1001 Jun 15, 2023
0e77721
Add `aws-smithy-types` dep to `idempotency_token` inlineable
ysaito1001 Jun 15, 2023
c449eb4
Update call site of `make_token` to use `token_provider`
ysaito1001 Jun 15, 2023
8d573f2
Revert `token_provider` to `make_token`
ysaito1001 Jun 15, 2023
79aa1ed
Merge branch 'main' into ysaito/frozen-layer-backed-service-config
ysaito1001 Jun 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions aws/rust-runtime/aws-credential-types/external-types.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
allowed_external_types = [
"aws_smithy_async::rt::sleep::SharedAsyncSleep",
"aws_smithy_types::config_bag::storable::Storable",
"aws_smithy_types::config_bag::storable::StoreReplace",
"aws_smithy_types::config_bag::storable::Storer",
]
9 changes: 9 additions & 0 deletions aws/rust-runtime/aws-credential-types/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use lazy_caching::Builder as LazyBuilder;
use no_caching::NoCredentialsCache;

use crate::provider::{future, SharedCredentialsProvider};
use aws_smithy_types::config_bag::{Storable, StoreReplace};
use std::sync::Arc;

/// Asynchronous Cached Credentials Provider
Expand Down Expand Up @@ -62,6 +63,10 @@ impl ProvideCachedCredentials for SharedCredentialsCache {
}
}

impl Storable for SharedCredentialsCache {
type Storer = StoreReplace<SharedCredentialsCache>;
}

#[derive(Clone, Debug)]
pub(crate) enum Inner {
Lazy(lazy_caching::Builder),
Expand Down Expand Up @@ -122,3 +127,7 @@ impl CredentialsCache {
}
}
}

impl Storable for CredentialsCache {
type Storer = StoreReplace<CredentialsCache>;
}
5 changes: 5 additions & 0 deletions aws/rust-runtime/aws-credential-types/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ construct credentials from hardcoded values.
//! ```

use crate::Credentials;
use aws_smithy_types::config_bag::{Storable, StoreReplace};
use std::sync::Arc;

/// Credentials provider errors
Expand Down Expand Up @@ -350,3 +351,7 @@ impl ProvideCredentials for SharedCredentialsProvider {
self.0.provide_credentials()
}
}

impl Storable for SharedCredentialsProvider {
type Storer = StoreReplace<SharedCredentialsProvider>;
}
5 changes: 4 additions & 1 deletion aws/rust-runtime/aws-types/external-types.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ allowed_external_types = [
"aws_credential_types::cache::CredentialsCache",
"aws_credential_types::provider::SharedCredentialsProvider",
"aws_smithy_async::rt::sleep::SharedAsyncSleep",
"aws_smithy_async::time::TimeSource",
"aws_smithy_async::time::SharedTimeSource",
"aws_smithy_async::time::TimeSource",
"aws_smithy_client::http_connector",
"aws_smithy_client::http_connector::HttpConnector",
"aws_smithy_http::endpoint::Endpoint",
"aws_smithy_http::endpoint::EndpointPrefix",
"aws_smithy_http::endpoint::error::InvalidEndpointError",
"aws_smithy_types::config_bag::storable::Storable",
"aws_smithy_types::config_bag::storable::StoreReplace",
"aws_smithy_types::config_bag::storable::Storer",
"aws_smithy_types::retry::RetryConfig",
"aws_smithy_types::timeout::TimeoutConfig",
"http::uri::Uri",
Expand Down
5 changes: 5 additions & 0 deletions aws/rust-runtime/aws-types/src/app_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

//! New-type for a configurable app name.

use aws_smithy_types::config_bag::{Storable, StoreReplace};
use std::borrow::Cow;
use std::error::Error;
use std::fmt;
Expand Down Expand Up @@ -38,6 +39,10 @@ impl fmt::Display for AppName {
}
}

impl Storable for AppName {
type Storer = StoreReplace<AppName>;
}

impl AppName {
/// Creates a new app name.
///
Expand Down
31 changes: 31 additions & 0 deletions aws/rust-runtime/aws-types/src/endpoint_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

//! Newtypes for endpoint-related parameters
//!
//! Parameters require newtypes so they have distinct types when stored in layers in config bag.

use aws_smithy_types::config_bag::{Storable, StoreReplace};

/// Newtype for `use_fips`
#[derive(Clone, Debug)]
pub struct UseFips(pub bool);
impl Storable for UseFips {
type Storer = StoreReplace<UseFips>;
}

/// Newtype for `use_dual_stack`
#[derive(Clone, Debug)]
pub struct UseDualStack(pub bool);
impl Storable for UseDualStack {
type Storer = StoreReplace<UseDualStack>;
}

/// Newtype for `endpoint_url`
#[derive(Clone, Debug)]
pub struct EndpointUrl(pub String);
impl Storable for EndpointUrl {
type Storer = StoreReplace<EndpointUrl>;
}
1 change: 1 addition & 0 deletions aws/rust-runtime/aws-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

pub mod app_name;
pub mod build_metadata;
pub mod endpoint_config;
#[doc(hidden)]
pub mod os_shim_internal;
pub mod region;
Expand Down
5 changes: 5 additions & 0 deletions aws/rust-runtime/aws-types/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

//! Region type for determining the endpoint to send requests to.

use aws_smithy_types::config_bag::{Storable, StoreReplace};
use std::borrow::Cow;
use std::fmt::{Display, Formatter};

Expand Down Expand Up @@ -35,6 +36,10 @@ impl Display for Region {
}
}

impl Storable for Region {
type Storer = StoreReplace<Region>;
}

impl Region {
/// Creates a new `Region` from the given string.
pub fn new(region: impl Into<Cow<'static, str>>) -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CredentialsCacheDecorator : ClientCodegenDecorator {
codegenContext: ClientCodegenContext,
baseCustomizations: List<ConfigCustomization>,
): List<ConfigCustomization> {
return baseCustomizations + CredentialCacheConfig(codegenContext.runtimeConfig)
return baseCustomizations + CredentialCacheConfig(codegenContext)
}

override fun operationCustomizations(
Expand All @@ -49,44 +49,65 @@ class CredentialsCacheDecorator : ClientCodegenDecorator {
/**
* Add a `.credentials_cache` field and builder to the `Config` for a given service
*/
class CredentialCacheConfig(runtimeConfig: RuntimeConfig) : ConfigCustomization() {
class CredentialCacheConfig(codegenContext: ClientCodegenContext) : ConfigCustomization() {
private val runtimeConfig = codegenContext.runtimeConfig
private val runtimeMode = codegenContext.smithyRuntimeMode
private val codegenScope = arrayOf(
"cache" to AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("cache"),
"provider" to AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("provider"),
"CredentialsCache" to AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("cache::CredentialsCache"),
"DefaultProvider" to defaultProvider(),
"SharedCredentialsCache" to AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("cache::SharedCredentialsCache"),
"SharedCredentialsProvider" to AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("provider::SharedCredentialsProvider"),
)

override fun section(section: ServiceConfig) = writable {
when (section) {
ServiceConfig.ConfigStruct -> rustTemplate(
"""pub(crate) credentials_cache: #{cache}::SharedCredentialsCache,""",
*codegenScope,
)

ServiceConfig.ConfigImpl -> rustTemplate(
"""
/// Returns the credentials cache.
pub fn credentials_cache(&self) -> #{cache}::SharedCredentialsCache {
self.credentials_cache.clone()
ServiceConfig.ConfigStruct -> {
if (runtimeMode.defaultToMiddleware) {
rustTemplate(
"""pub(crate) credentials_cache: #{SharedCredentialsCache},""",
*codegenScope,
)
}
""",
*codegenScope,
)
}

ServiceConfig.ConfigImpl -> {
if (runtimeMode.defaultToOrchestrator) {
rustTemplate(
"""
/// Returns the credentials cache.
pub fn credentials_cache(&self) -> #{SharedCredentialsCache} {
self.inner.load::<#{SharedCredentialsCache}>().expect("credentials cache should be set").clone()
}
""",
*codegenScope,
)
} else {
rustTemplate(
"""
/// Returns the credentials cache.
pub fn credentials_cache(&self) -> #{SharedCredentialsCache} {
self.credentials_cache.clone()
}
""",
*codegenScope,
)
}
}

ServiceConfig.BuilderStruct ->
rustTemplate("credentials_cache: Option<#{cache}::CredentialsCache>,", *codegenScope)
rustTemplate("credentials_cache: Option<#{CredentialsCache}>,", *codegenScope)

ServiceConfig.BuilderImpl -> {
rustTemplate(
"""
/// Sets the credentials cache for this service
pub fn credentials_cache(mut self, credentials_cache: #{cache}::CredentialsCache) -> Self {
pub fn credentials_cache(mut self, credentials_cache: #{CredentialsCache}) -> Self {
self.set_credentials_cache(Some(credentials_cache));
self
}

/// Sets the credentials cache for this service
pub fn set_credentials_cache(&mut self, credentials_cache: Option<#{cache}::CredentialsCache>) -> &mut Self {
pub fn set_credentials_cache(&mut self, credentials_cache: Option<#{CredentialsCache}>) -> &mut Self {
self.credentials_cache = credentials_cache;
self
}
Expand All @@ -95,29 +116,56 @@ class CredentialCacheConfig(runtimeConfig: RuntimeConfig) : ConfigCustomization(
)
}

ServiceConfig.BuilderBuild -> rustTemplate(
"""
credentials_cache: self
.credentials_cache
.unwrap_or_else({
let sleep = self.sleep_impl.clone();
|| match sleep {
Some(sleep) => {
#{cache}::CredentialsCache::lazy_builder()
.sleep(sleep)
.into_credentials_cache()
}
None => #{cache}::CredentialsCache::lazy(),
}
})
.create_cache(
self.credentials_provider.unwrap_or_else(|| {
#{provider}::SharedCredentialsProvider::new(#{DefaultProvider})
})
),
""",
*codegenScope,
)
ServiceConfig.BuilderBuild -> {
if (runtimeMode.defaultToOrchestrator) {
rustTemplate(
"""
layer.store_put(
self.credentials_cache
.unwrap_or_else({
let sleep = self.sleep_impl.clone();
|| match sleep {
Some(sleep) => {
#{CredentialsCache}::lazy_builder()
.sleep(sleep)
.into_credentials_cache()
}
None => #{CredentialsCache}::lazy(),
}
})
.create_cache(self.credentials_provider.unwrap_or_else(|| {
#{SharedCredentialsProvider}::new(#{DefaultProvider})
})),
);
""",
*codegenScope,
)
} else {
rustTemplate(
"""
credentials_cache: self
.credentials_cache
.unwrap_or_else({
let sleep = self.sleep_impl.clone();
|| match sleep {
Some(sleep) => {
#{CredentialsCache}::lazy_builder()
.sleep(sleep)
.into_credentials_cache()
}
None => #{CredentialsCache}::lazy(),
}
})
.create_cache(
self.credentials_provider.unwrap_or_else(|| {
#{SharedCredentialsProvider}::new(#{DefaultProvider})
})
),
""",
*codegenScope,
)
}
}

else -> emptySection
}
Expand Down
Loading