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

Sourcing service config from the environment. #3493

Merged
merged 32 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2339db5
add support for service env config
Velfi Mar 12, 2024
02485ac
Merge remote-tracking branch 'origin/main' into zhessler-service-env-…
Velfi Mar 15, 2024
1c39d00
update tests
Velfi Mar 19, 2024
2d574ae
Merge branch 'main' into zhessler-service-env-config
Velfi Mar 19, 2024
6aee5d9
move test JSONs
Velfi Mar 19, 2024
d847bc8
fix clippy lints
Velfi Mar 19, 2024
4504106
fix codegen attribute
Velfi Mar 19, 2024
5746e52
fix integration test import
Velfi Mar 19, 2024
f1ba0c0
fix usage of fs_util
Velfi Mar 19, 2024
d98aa86
add support for s3 express env config
Velfi Mar 19, 2024
699e44a
Merge branch 'main' into zhessler-service-env-config
Velfi Mar 19, 2024
0e4e3be
remove comment
Velfi Mar 20, 2024
8fdcb11
Update aws/rust-runtime/aws-types/src/sdk_config.rs
Velfi Mar 25, 2024
5bc1fa1
Update aws/rust-runtime/aws-runtime/src/profile/section.rs
Velfi Mar 25, 2024
28c2453
Merge remote-tracking branch 'origin/main' into zhessler-service-env-…
Velfi Mar 25, 2024
28102c3
big rename of env config types
Velfi Mar 25, 2024
fca10de
add missing doc comment
Velfi Mar 25, 2024
25fea3c
remove unnecessary async
Velfi Mar 25, 2024
d29330b
Merge branch 'main' into zhessler-service-env-config
Velfi Mar 25, 2024
fc1c32c
appease the versioner
Velfi Mar 26, 2024
cd423f3
fix logging test broken by crate move
Velfi Mar 26, 2024
69ea83a
update external-types.toml
Velfi Mar 26, 2024
e98f476
Merge remote-tracking branch 'origin/main' into zhessler-service-env-…
Velfi Mar 28, 2024
02d7ae9
PR comments update
Velfi Mar 28, 2024
d7744fa
undo change to parse_property_line (old one was better)
Velfi Mar 28, 2024
480ab45
Merge branch 'main' into zhessler-service-env-config
Velfi Mar 28, 2024
ebfab85
remove unnecessary s3 env config test
Velfi Mar 28, 2024
590c000
add changelog entry
Velfi Mar 28, 2024
62f21dc
Merge remote-tracking branch 'origin/main' into zhessler-service-env-…
Velfi Mar 28, 2024
631a3e8
remove duplicated changelog entry
Velfi Mar 29, 2024
a8e3ac3
Update aws/rust-runtime/aws-runtime/src/env_config/file.rs
Velfi Mar 29, 2024
455dc51
Merge branch 'main' into zhessler-service-env-config
Velfi Mar 29, 2024
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
24 changes: 13 additions & 11 deletions aws/rust-runtime/aws-config/src/default_provider/app_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

use crate::provider_config::ProviderConfig;
use crate::standard_property::{PropertyResolutionError, StandardProperty};
use aws_runtime::env_config::{EnvConfigError, EnvConfigValue};
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::app_name::{AppName, InvalidAppName};

Expand Down Expand Up @@ -56,22 +56,24 @@ impl Builder {
self
}

async fn fallback_app_name(
&self,
) -> Result<Option<AppName>, PropertyResolutionError<InvalidAppName>> {
StandardProperty::new()
async fn fallback_app_name(&self) -> Result<Option<AppName>, EnvConfigError<InvalidAppName>> {
let env = self.provider_config.env();
let profiles = self.provider_config.profile().await;

EnvConfigValue::new()
.profile("sdk-ua-app-id")
.validate(&self.provider_config, |name| AppName::new(name.to_string()))
.await
.validate(&env, profiles, |name| AppName::new(name.to_string()))
}

/// Build an [`AppName`] from the default chain
pub async fn app_name(self) -> Option<AppName> {
let standard = StandardProperty::new()
let env = self.provider_config.env();
let profiles = self.provider_config.profile().await;

let standard = EnvConfigValue::new()
.env("AWS_SDK_UA_APP_ID")
.profile("sdk_ua_app_id")
.validate(&self.provider_config, |name| AppName::new(name.to_string()))
.await;
.validate(&env, profiles, |name| AppName::new(name.to_string()));
let with_fallback = match standard {
Ok(None) => self.fallback_app_name().await,
other => other,
Expand All @@ -87,9 +89,9 @@ impl Builder {
#[cfg(test)]
mod tests {
use super::*;
use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
use crate::provider_config::ProviderConfig;
use crate::test_case::{no_traffic_client, InstantSleep};
use aws_runtime::profile::profile_file::{ProfileFileKind, ProfileFiles};
use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
use aws_types::os_shim_internal::{Env, Fs};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::environment::parse_url;
use crate::provider_config::ProviderConfig;
use crate::standard_property::StandardProperty;
use aws_runtime::env_config::EnvConfigValue;
use aws_smithy_types::error::display::DisplayErrorContext;

mod env {
Expand All @@ -24,11 +24,13 @@ mod profile_key {
///
/// If invalid values are found, the provider will return None and an error will be logged.
pub async fn endpoint_url_provider(provider_config: &ProviderConfig) -> Option<String> {
StandardProperty::new()
let env = provider_config.env();
let profiles = provider_config.profile().await;

EnvConfigValue::new()
.env(env::ENDPOINT_URL)
.profile(profile_key::ENDPOINT_URL)
.validate(provider_config, parse_url)
.await
.validate(&env, profiles, parse_url)
.map_err(
|err| tracing::warn!(err = %DisplayErrorContext(&err), "invalid value for endpoint URL setting"),
)
Expand All @@ -39,8 +41,8 @@ pub async fn endpoint_url_provider(provider_config: &ProviderConfig) -> Option<S
mod test {
use super::endpoint_url_provider;
use super::env;
use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
use crate::provider_config::ProviderConfig;
use aws_runtime::profile::profile_file::{ProfileFileKind, ProfileFiles};
use aws_types::os_shim_internal::{Env, Fs};
use tracing_test::traced_test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::environment::parse_bool;
use crate::provider_config::ProviderConfig;
use crate::standard_property::StandardProperty;
use aws_runtime::env_config::EnvConfigValue;
use aws_smithy_types::error::display::DisplayErrorContext;

mod env {
Expand All @@ -26,11 +26,13 @@ mod profile_key {
pub async fn ignore_configured_endpoint_urls_provider(
provider_config: &ProviderConfig,
) -> Option<bool> {
StandardProperty::new()
let env = provider_config.env();
let profiles = provider_config.profile().await;

EnvConfigValue::new()
.env(env::IGNORE_CONFIGURED_ENDPOINT_URLS)
.profile(profile_key::IGNORE_CONFIGURED_ENDPOINT_URLS)
.validate(provider_config, parse_bool)
.await
.validate(&env, profiles, parse_bool)
.map_err(
|err| tracing::warn!(err = %DisplayErrorContext(&err), "invalid value for 'ignore configured endpoint URLs' setting"),
)
Expand All @@ -41,8 +43,8 @@ pub async fn ignore_configured_endpoint_urls_provider(
mod test {
use super::env;
use super::ignore_configured_endpoint_urls_provider;
use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
use crate::provider_config::ProviderConfig;
use aws_runtime::profile::profile_file::{ProfileFileKind, ProfileFiles};
use aws_types::os_shim_internal::{Env, Fs};
use tracing_test::traced_test;

Expand Down
32 changes: 17 additions & 15 deletions aws/rust-runtime/aws-config/src/default_provider/retry_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::provider_config::ProviderConfig;
use crate::retry::error::{RetryConfigError, RetryConfigErrorKind};
use crate::standard_property::{PropertyResolutionError, StandardProperty};
use aws_runtime::env_config::{EnvConfigError, EnvConfigValue};
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_smithy_types::retry::{RetryConfig, RetryMode};
use std::str::FromStr;
Expand Down Expand Up @@ -101,29 +101,31 @@ impl Builder {

pub(crate) async fn try_retry_config(
self,
) -> Result<RetryConfig, PropertyResolutionError<RetryConfigError>> {
// Both of these can return errors due to invalid config settings and we want to surface those as early as possible
) -> Result<RetryConfig, EnvConfigError<RetryConfigError>> {
let env = self.provider_config.env();
let profiles = self.provider_config.profile().await;
// Both of these can return errors due to invalid config settings, and we want to surface those as early as possible
// hence, we'll panic if any config values are invalid (missing values are OK though)
// We match this instead of unwrapping so we can print the error with the `Display` impl instead of the `Debug` impl that unwrap uses
// We match this instead of unwrapping, so we can print the error with the `Display` impl instead of the `Debug` impl that unwrap uses
let mut retry_config = RetryConfig::standard();
let max_attempts = StandardProperty::new()
let max_attempts = EnvConfigValue::new()
.env(env::MAX_ATTEMPTS)
.profile(profile_keys::MAX_ATTEMPTS)
.validate(&self.provider_config, validate_max_attempts);
.validate(&env, profiles, validate_max_attempts);

let retry_mode = StandardProperty::new()
let retry_mode = EnvConfigValue::new()
.env(env::RETRY_MODE)
.profile(profile_keys::RETRY_MODE)
.validate(&self.provider_config, |s| {
.validate(&env, profiles, |s| {
RetryMode::from_str(s)
.map_err(|err| RetryConfigErrorKind::InvalidRetryMode { source: err }.into())
});

if let Some(max_attempts) = max_attempts.await? {
if let Some(max_attempts) = max_attempts? {
retry_config = retry_config.with_max_attempts(max_attempts);
}

if let Some(retry_mode) = retry_mode.await? {
if let Some(retry_mode) = retry_mode? {
retry_config = retry_config.with_retry_mode(retry_mode);
}

Expand All @@ -146,12 +148,12 @@ mod test {
use crate::retry::{
error::RetryConfigError, error::RetryConfigErrorKind, RetryConfig, RetryMode,
};
use crate::standard_property::PropertyResolutionError;
use aws_runtime::env_config::EnvConfigError;
use aws_types::os_shim_internal::{Env, Fs};

async fn test_provider(
vars: &[(&str, &str)],
) -> Result<RetryConfig, PropertyResolutionError<RetryConfigError>> {
) -> Result<RetryConfig, EnvConfigError<RetryConfigError>> {
super::Builder::default()
.configure(&ProviderConfig::no_configuration().with_env(Env::from_slice(vars)))
.try_retry_config()
Expand Down Expand Up @@ -296,7 +298,7 @@ max_attempts = potato
test_provider(&[(env::MAX_ATTEMPTS, "not an integer")])
.await
.unwrap_err()
.err,
.err(),
RetryConfigError {
kind: RetryConfigErrorKind::FailedToParseMaxAttempts { .. }
}
Expand Down Expand Up @@ -327,8 +329,8 @@ max_attempts = potato
async fn disallow_zero_max_attempts() {
let err = test_provider(&[(env::MAX_ATTEMPTS, "0")])
.await
.unwrap_err()
.err;
.unwrap_err();
let err = err.err();
assert!(matches!(
err,
RetryConfigError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::environment::parse_bool;
use crate::provider_config::ProviderConfig;
use crate::standard_property::StandardProperty;
use aws_runtime::env_config::EnvConfigValue;
use aws_smithy_types::error::display::DisplayErrorContext;

mod env {
Expand All @@ -17,11 +17,13 @@ mod profile_key {
}

pub(crate) async fn use_dual_stack_provider(provider_config: &ProviderConfig) -> Option<bool> {
StandardProperty::new()
let env = provider_config.env();
let profiles = provider_config.profile().await;

EnvConfigValue::new()
.env(env::USE_DUAL_STACK)
.profile(profile_key::USE_DUAL_STACK)
.validate(provider_config, parse_bool)
.await
.validate(&env, profiles, parse_bool)
.map_err(
|err| tracing::warn!(err = %DisplayErrorContext(&err), "invalid value for dual-stack setting"),
)
Expand All @@ -31,8 +33,8 @@ pub(crate) async fn use_dual_stack_provider(provider_config: &ProviderConfig) ->
#[cfg(test)]
mod test {
use crate::default_provider::use_dual_stack::use_dual_stack_provider;
use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
use crate::provider_config::ProviderConfig;
use aws_runtime::profile::profile_file::{ProfileFileKind, ProfileFiles};
use aws_types::os_shim_internal::{Env, Fs};
use tracing_test::traced_test;

Expand Down
12 changes: 7 additions & 5 deletions aws/rust-runtime/aws-config/src/default_provider/use_fips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::environment::parse_bool;
use crate::provider_config::ProviderConfig;
use crate::standard_property::StandardProperty;
use aws_runtime::env_config::EnvConfigValue;
use aws_smithy_types::error::display::DisplayErrorContext;

mod env {
Expand All @@ -24,11 +24,13 @@ mod profile_key {
///
/// If invalid values are found, the provider will return None and an error will be logged.
pub async fn use_fips_provider(provider_config: &ProviderConfig) -> Option<bool> {
StandardProperty::new()
let env = provider_config.env();
let profiles = provider_config.profile().await;

EnvConfigValue::new()
.env(env::USE_FIPS)
.profile(profile_key::USE_FIPS)
.validate(provider_config, parse_bool)
.await
.validate(&env, profiles, parse_bool)
.map_err(
|err| tracing::warn!(err = %DisplayErrorContext(&err), "invalid value for FIPS setting"),
)
Expand All @@ -38,8 +40,8 @@ pub async fn use_fips_provider(provider_config: &ProviderConfig) -> Option<bool>
#[cfg(test)]
mod test {
use crate::default_provider::use_fips::use_fips_provider;
use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
use crate::provider_config::ProviderConfig;
use aws_runtime::profile::profile_file::{ProfileFileKind, ProfileFiles};
use aws_types::os_shim_internal::{Env, Fs};
use tracing_test::traced_test;

Expand Down
27 changes: 27 additions & 0 deletions aws/rust-runtime/aws-config/src/env_service_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

use aws_runtime::env_config::EnvConfigValue;
use aws_runtime::profile::profile_set::ProfileSet;
use aws_types::os_shim_internal::Env;
use aws_types::service_config::{LoadServiceConfig, ServiceConfigKey};

#[derive(Debug)]
pub(crate) struct EnvServiceConfig {
pub(crate) env: Env,
pub(crate) profiles: ProfileSet,
}

impl LoadServiceConfig for EnvServiceConfig {
fn load_config(&self, key: ServiceConfigKey<'_>) -> Option<String> {
let (value, _source) = EnvConfigValue::new()
.env(key.env())
.profile(key.profile())
.service_id(key.service_id())
.load(&self.env, Some(&self.profiles))?;

Some(value.to_string())
}
}
Loading
Loading