aws_config/default_provider/
disable_clock_skew_correction.rs1use 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 DISABLE_CLOCK_SKEW_CORRECTION: &str = "AWS_DISABLE_CLOCK_SKEW_CORRECTION";
13}
14
15mod profile_key {
16 pub(super) const DISABLE_CLOCK_SKEW_CORRECTION: &str = "disable_clock_skew_correction";
17}
18
19pub(crate) async fn disable_clock_skew_correction_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::DISABLE_CLOCK_SKEW_CORRECTION)
34 .profile(profile_key::DISABLE_CLOCK_SKEW_CORRECTION)
35 .validate(&env, profiles, parse_bool)
36 .map_err(
37 |err| tracing::warn!(err = %DisplayErrorContext(&err), "invalid value for `disable clock skew correction` setting"),
38 )
39 .unwrap_or(None)
40}
41
42#[cfg(test)]
43mod test {
44 use super::disable_clock_skew_correction_provider;
45 #[allow(deprecated)]
46 use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
47 use crate::provider_config::ProviderConfig;
48 use aws_types::os_shim_internal::{Env, Fs};
49 use tracing_test::traced_test;
50
51 #[tokio::test]
52 #[traced_test]
53 async fn log_error_on_invalid_value() {
54 let conf = ProviderConfig::empty().with_env(Env::from_slice(&[(
55 "AWS_DISABLE_CLOCK_SKEW_CORRECTION",
56 "not-a-boolean",
57 )]));
58 assert_eq!(disable_clock_skew_correction_provider(&conf).await, None);
59 assert!(logs_contain(
60 "invalid value for `disable clock skew correction` setting"
61 ));
62 assert!(logs_contain("AWS_DISABLE_CLOCK_SKEW_CORRECTION"));
63 }
64
65 #[tokio::test]
66 async fn environment_priority() {
67 let conf = ProviderConfig::empty()
68 .with_env(Env::from_slice(&[(
69 "AWS_DISABLE_CLOCK_SKEW_CORRECTION",
70 "TRUE",
71 )]))
72 .with_profile_config(
73 Some(
74 #[allow(deprecated)]
75 ProfileFiles::builder()
76 .with_file(
77 #[allow(deprecated)]
78 ProfileFileKind::Config,
79 "conf",
80 )
81 .build(),
82 ),
83 None,
84 )
85 .with_fs(Fs::from_slice(&[(
86 "conf",
87 "[default]\ndisable_clock_skew_correction = false",
88 )]));
89 assert_eq!(
90 disable_clock_skew_correction_provider(&conf).await,
91 Some(true)
92 );
93 }
94
95 #[tokio::test]
96 async fn profile_config_works() {
97 let conf = ProviderConfig::empty()
98 .with_profile_config(
99 Some(
100 #[allow(deprecated)]
101 ProfileFiles::builder()
102 .with_file(
103 #[allow(deprecated)]
104 ProfileFileKind::Config,
105 "conf",
106 )
107 .build(),
108 ),
109 None,
110 )
111 .with_fs(Fs::from_slice(&[(
112 "conf",
113 "[default]\ndisable_clock_skew_correction = true",
114 )]));
115 assert_eq!(
116 disable_clock_skew_correction_provider(&conf).await,
117 Some(true)
118 );
119 }
120}