aws_config/default_provider/
ignore_configured_endpoint_urls.rs
1use crate::environment::parse_bool;
7use crate::provider_config::ProviderConfig;
8use aws_runtime::env_config::EnvConfigValue;
9use aws_smithy_types::error::display::DisplayErrorContext;
10
11mod env {
12 pub(super) const IGNORE_CONFIGURED_ENDPOINT_URLS: &str = "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS";
13}
14
15mod profile_key {
16 pub(super) const IGNORE_CONFIGURED_ENDPOINT_URLS: &str = "ignore_configured_endpoint_urls";
17}
18
19pub async fn ignore_configured_endpoint_urls_provider(
27 provider_config: &ProviderConfig,
28) -> Option<bool> {
29 let env = provider_config.env();
30 let profiles = provider_config.profile().await;
31
32 EnvConfigValue::new()
33 .env(env::IGNORE_CONFIGURED_ENDPOINT_URLS)
34 .profile(profile_key::IGNORE_CONFIGURED_ENDPOINT_URLS)
35 .validate(&env, profiles, parse_bool)
36 .map_err(
37 |err| tracing::warn!(err = %DisplayErrorContext(&err), "invalid value for 'ignore configured endpoint URLs' setting"),
38 )
39 .unwrap_or(None)
40}
41
42#[cfg(test)]
43mod test {
44 use super::env;
45 use super::ignore_configured_endpoint_urls_provider;
46 #[allow(deprecated)]
47 use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
48 use crate::provider_config::ProviderConfig;
49 use aws_types::os_shim_internal::{Env, Fs};
50 use tracing_test::traced_test;
51
52 #[tokio::test]
53 #[traced_test]
54 async fn log_error_on_invalid_value() {
55 let conf = ProviderConfig::empty().with_env(Env::from_slice(&[(
56 env::IGNORE_CONFIGURED_ENDPOINT_URLS,
57 "not-a-boolean",
58 )]));
59 assert_eq!(None, ignore_configured_endpoint_urls_provider(&conf).await,);
60 assert!(logs_contain(
61 "invalid value for 'ignore configured endpoint URLs' setting"
62 ));
63 assert!(logs_contain(env::IGNORE_CONFIGURED_ENDPOINT_URLS));
64 }
65
66 #[tokio::test]
67 #[traced_test]
68 async fn environment_priority() {
69 let conf = ProviderConfig::empty()
70 .with_env(Env::from_slice(&[(
71 env::IGNORE_CONFIGURED_ENDPOINT_URLS,
72 "TRUE",
73 )]))
74 .with_profile_config(
75 Some(
76 #[allow(deprecated)]
77 ProfileFiles::builder()
78 .with_file(
79 #[allow(deprecated)]
80 ProfileFileKind::Config,
81 "conf",
82 )
83 .build(),
84 ),
85 None,
86 )
87 .with_fs(Fs::from_slice(&[(
88 "conf",
89 "[default]\nignore_configured_endpoint_urls = false",
90 )]));
91 assert_eq!(
92 Some(true),
93 ignore_configured_endpoint_urls_provider(&conf).await,
94 );
95 }
96}