From ea2ae7bfc6d8ba1daf7a4648a4027b7268f56283 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Mon, 13 Jun 2022 13:34:11 -0700 Subject: [PATCH] Add lints to `aws-config` (#1421) * Add `unreachable_pub` lint to `aws-config` * Add `missing_debug_implementations` lint to `aws-config` * Add `rust_2018_idioms` lint to `aws-config` * Update changelog --- CHANGELOG.next.toml | 6 +++ aws/rust-runtime/aws-config/src/cache.rs | 6 +-- .../aws-config/src/credential_process.rs | 2 +- .../src/default_provider/app_name.rs | 2 +- .../src/default_provider/credentials.rs | 2 +- .../aws-config/src/default_provider/region.rs | 4 +- .../src/default_provider/retry_config.rs | 2 +- .../src/default_provider/timeout_config.rs | 2 +- aws/rust-runtime/aws-config/src/ecs.rs | 2 +- .../aws-config/src/environment/region.rs | 2 +- aws/rust-runtime/aws-config/src/fs_util.rs | 2 +- .../src/http_credential_provider.rs | 4 +- .../aws-config/src/imds/client.rs | 10 ++--- .../aws-config/src/imds/credentials.rs | 2 +- .../aws-config/src/imds/region.rs | 4 +- .../aws-config/src/json_credentials.rs | 2 +- aws/rust-runtime/aws-config/src/lib.rs | 9 +++- .../aws-config/src/meta/credentials/chain.rs | 2 +- .../src/meta/credentials/lazy_caching.rs | 4 +- .../aws-config/src/meta/region.rs | 15 +++---- .../aws-config/src/profile/app_name.rs | 2 +- .../aws-config/src/profile/credentials.rs | 2 +- .../src/profile/credentials/exec.rs | 36 ++++++++-------- .../src/profile/credentials/repr.rs | 42 +++++++++---------- .../aws-config/src/profile/mod.rs | 8 +++- .../src/profile/parser/normalize.rs | 8 ++-- .../aws-config/src/profile/parser/parse.rs | 6 +-- .../aws-config/src/profile/parser/source.rs | 18 ++++---- .../aws-config/src/profile/region.rs | 4 +- .../aws-config/src/profile/retry_config.rs | 2 +- .../aws-config/src/profile/timeout_config.rs | 2 +- .../aws-config/src/sts/assume_role.rs | 3 +- aws/rust-runtime/aws-config/src/test_case.rs | 24 ++++++----- .../aws-config/src/web_identity_token.rs | 4 +- 34 files changed, 135 insertions(+), 110 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index be06f2737..16c847df7 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -16,3 +16,9 @@ message = "Fix bug in profile file credential provider where a missing `default` references = ["aws-sdk-rust#547", "smithy-rs#1458"] meta = { "breaking" = false, "tada" = false, "bug" = true } author = "rcoh" + +[[aws-sdk-rust]] +message = "Add `Debug` implementation to several types in `aws-config`" +references = ["smithy-rs#1421"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "jdisanti" \ No newline at end of file diff --git a/aws/rust-runtime/aws-config/src/cache.rs b/aws/rust-runtime/aws-config/src/cache.rs index 9ad535d72..b98b1d6b8 100644 --- a/aws/rust-runtime/aws-config/src/cache.rs +++ b/aws/rust-runtime/aws-config/src/cache.rs @@ -38,7 +38,7 @@ impl ExpiringCache where T: Clone, { - pub fn new(buffer_time: Duration) -> Self { + pub(crate) fn new(buffer_time: Duration) -> Self { ExpiringCache { buffer_time, value: Arc::new(RwLock::new(OnceCell::new())), @@ -64,7 +64,7 @@ where /// and the others will await that thread's result rather than multiple refreshes occurring. /// The function given to acquire a value future, `f`, will not be called /// if another thread is chosen to load the value. - pub async fn get_or_load(&self, f: F) -> Result + pub(crate) async fn get_or_load(&self, f: F) -> Result where F: FnOnce() -> Fut, Fut: Future>, @@ -75,7 +75,7 @@ where } /// If the value is expired, clears the cache. Otherwise, yields the current value. - pub async fn yield_or_clear_if_expired(&self, now: SystemTime) -> Option { + pub(crate) async fn yield_or_clear_if_expired(&self, now: SystemTime) -> Option { // Short-circuit if the value is not expired if let Some((value, expiry)) = self.value.read().await.get() { if !expired(*expiry, self.buffer_time, now) { diff --git a/aws/rust-runtime/aws-config/src/credential_process.rs b/aws/rust-runtime/aws-config/src/credential_process.rs index 77c8b224f..5a75089ac 100644 --- a/aws/rust-runtime/aws-config/src/credential_process.rs +++ b/aws/rust-runtime/aws-config/src/credential_process.rs @@ -178,7 +178,7 @@ impl CredentialProcessProvider { /// Keys are case insensitive. pub(crate) fn parse_credential_process_json_credentials( credentials_response: &str, -) -> Result { +) -> Result, InvalidJsonCredentials> { let mut version = None; let mut access_key_id = None; let mut secret_access_key = None; diff --git a/aws/rust-runtime/aws-config/src/default_provider/app_name.rs b/aws/rust-runtime/aws-config/src/default_provider/app_name.rs index 05a73051d..af8dcfa00 100644 --- a/aws/rust-runtime/aws-config/src/default_provider/app_name.rs +++ b/aws/rust-runtime/aws-config/src/default_provider/app_name.rs @@ -18,7 +18,7 @@ pub fn default_provider() -> Builder { } /// Default provider builder for [`AppName`] -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { env_provider: EnvironmentVariableAppNameProvider, profile_file: app_name::Builder, diff --git a/aws/rust-runtime/aws-config/src/default_provider/credentials.rs b/aws/rust-runtime/aws-config/src/default_provider/credentials.rs index 64ba80a11..ec6885694 100644 --- a/aws/rust-runtime/aws-config/src/default_provider/credentials.rs +++ b/aws/rust-runtime/aws-config/src/default_provider/credentials.rs @@ -85,7 +85,7 @@ impl ProvideCredentials for DefaultCredentialsChain { } /// Builder for [`DefaultCredentialsChain`](DefaultCredentialsChain) -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { profile_file_builder: crate::profile::credentials::Builder, web_identity_builder: crate::web_identity_token::Builder, diff --git a/aws/rust-runtime/aws-config/src/default_provider/region.rs b/aws/rust-runtime/aws-config/src/default_provider/region.rs index f4d15b17a..f7b882446 100644 --- a/aws/rust-runtime/aws-config/src/default_provider/region.rs +++ b/aws/rust-runtime/aws-config/src/default_provider/region.rs @@ -37,7 +37,7 @@ impl DefaultRegionChain { } /// Builder for [DefaultRegionChain] -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { env_provider: EnvironmentVariableRegionProvider, profile_file: profile::region::Builder, @@ -73,7 +73,7 @@ impl Builder { } impl ProvideRegion for DefaultRegionChain { - fn region(&self) -> crate::meta::region::future::ProvideRegion { + fn region(&self) -> crate::meta::region::future::ProvideRegion<'_> { ProvideRegion::region(&self.0) } } diff --git a/aws/rust-runtime/aws-config/src/default_provider/retry_config.rs b/aws/rust-runtime/aws-config/src/default_provider/retry_config.rs index 7314c2850..4e8a4c00a 100644 --- a/aws/rust-runtime/aws-config/src/default_provider/retry_config.rs +++ b/aws/rust-runtime/aws-config/src/default_provider/retry_config.rs @@ -50,7 +50,7 @@ pub fn default_provider() -> Builder { } /// Builder for RetryConfig that checks the environment and aws profile for configuration -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { env_provider: EnvironmentVariableRetryConfigProvider, profile_file: profile::retry_config::Builder, diff --git a/aws/rust-runtime/aws-config/src/default_provider/timeout_config.rs b/aws/rust-runtime/aws-config/src/default_provider/timeout_config.rs index 7b5563ed1..868d68660 100644 --- a/aws/rust-runtime/aws-config/src/default_provider/timeout_config.rs +++ b/aws/rust-runtime/aws-config/src/default_provider/timeout_config.rs @@ -45,7 +45,7 @@ pub fn default_provider() -> Builder { } /// Builder for [`timeout::Config`](aws_smithy_types::timeout::Config) that checks the environment variables and AWS profile files for configuration -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { env_provider: EnvironmentVariableTimeoutConfigProvider, profile_file: profile::timeout_config::Builder, diff --git a/aws/rust-runtime/aws-config/src/ecs.rs b/aws/rust-runtime/aws-config/src/ecs.rs index 1f491cea8..8b642b554 100644 --- a/aws/rust-runtime/aws-config/src/ecs.rs +++ b/aws/rust-runtime/aws-config/src/ecs.rs @@ -154,7 +154,7 @@ impl Provider { } } - pub async fn make(builder: Builder) -> Self { + async fn make(builder: Builder) -> Self { let provider_config = builder.provider_config.unwrap_or_default(); let env = provider_config.env(); let uri = match Self::uri(env, builder.dns).await { diff --git a/aws/rust-runtime/aws-config/src/environment/region.rs b/aws/rust-runtime/aws-config/src/environment/region.rs index c7395e871..48859cbe4 100644 --- a/aws/rust-runtime/aws-config/src/environment/region.rs +++ b/aws/rust-runtime/aws-config/src/environment/region.rs @@ -32,7 +32,7 @@ impl EnvironmentVariableRegionProvider { } impl ProvideRegion for EnvironmentVariableRegionProvider { - fn region(&self) -> future::ProvideRegion { + fn region(&self) -> future::ProvideRegion<'_> { let region = self .env .get("AWS_REGION") diff --git a/aws/rust-runtime/aws-config/src/fs_util.rs b/aws/rust-runtime/aws-config/src/fs_util.rs index 74927188d..89af426d8 100644 --- a/aws/rust-runtime/aws-config/src/fs_util.rs +++ b/aws/rust-runtime/aws-config/src/fs_util.rs @@ -12,7 +12,7 @@ pub(crate) enum Os { } impl Os { - pub fn real() -> Self { + pub(crate) fn real() -> Self { match std::env::consts::OS { "windows" => Os::Windows, _ => Os::NotWindows, diff --git a/aws/rust-runtime/aws-config/src/http_credential_provider.rs b/aws/rust-runtime/aws-config/src/http_credential_provider.rs index d77037522..d77aa81ca 100644 --- a/aws/rust-runtime/aws-config/src/http_credential_provider.rs +++ b/aws/rust-runtime/aws-config/src/http_credential_provider.rs @@ -42,11 +42,11 @@ pub(crate) struct HttpCredentialProvider { } impl HttpCredentialProvider { - pub fn builder() -> Builder { + pub(crate) fn builder() -> Builder { Builder::default() } - pub async fn credentials(&self, auth: Option) -> credentials::Result { + pub(crate) async fn credentials(&self, auth: Option) -> credentials::Result { let credentials = self.client.call(self.operation(auth)).await; match credentials { Ok(creds) => Ok(creds), diff --git a/aws/rust-runtime/aws-config/src/imds/client.rs b/aws/rust-runtime/aws-config/src/imds/client.rs index cd61d7fc2..a279c15a6 100644 --- a/aws/rust-runtime/aws-config/src/imds/client.rs +++ b/aws/rust-runtime/aws-config/src/imds/client.rs @@ -132,7 +132,7 @@ pub(super) struct LazyClient { } impl LazyClient { - pub fn from_ready_client(client: Client) -> Self { + pub(super) fn from_ready_client(client: Client) -> Self { Self { client: OnceCell::from(Ok(client)), // the builder will never be used in this case @@ -575,13 +575,13 @@ impl Builder { } mod env { - pub const ENDPOINT: &str = "AWS_EC2_METADATA_SERVICE_ENDPOINT"; - pub const ENDPOINT_MODE: &str = "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE"; + pub(super) const ENDPOINT: &str = "AWS_EC2_METADATA_SERVICE_ENDPOINT"; + pub(super) const ENDPOINT_MODE: &str = "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE"; } mod profile_keys { - pub const ENDPOINT: &str = "ec2_metadata_service_endpoint"; - pub const ENDPOINT_MODE: &str = "ec2_metadata_service_endpoint_mode"; + pub(super) const ENDPOINT: &str = "ec2_metadata_service_endpoint"; + pub(super) const ENDPOINT_MODE: &str = "ec2_metadata_service_endpoint_mode"; } /// Endpoint Configuration Abstraction diff --git a/aws/rust-runtime/aws-config/src/imds/credentials.rs b/aws/rust-runtime/aws-config/src/imds/credentials.rs index 28f4d4b22..9161b3496 100644 --- a/aws/rust-runtime/aws-config/src/imds/credentials.rs +++ b/aws/rust-runtime/aws-config/src/imds/credentials.rs @@ -155,7 +155,7 @@ impl ImdsCredentialsProvider { )); } tracing::debug!("loading credentials from IMDS"); - let profile: Cow = match &self.profile { + let profile: Cow<'_, str> = match &self.profile { Some(profile) => profile.into(), None => self.get_profile_uncached().await?.into(), }; diff --git a/aws/rust-runtime/aws-config/src/imds/region.rs b/aws/rust-runtime/aws-config/src/imds/region.rs index 88f5945ac..e8516a446 100644 --- a/aws/rust-runtime/aws-config/src/imds/region.rs +++ b/aws/rust-runtime/aws-config/src/imds/region.rs @@ -65,7 +65,7 @@ impl ImdsRegionProvider { } impl ProvideRegion for ImdsRegionProvider { - fn region(&self) -> future::ProvideRegion { + fn region(&self) -> future::ProvideRegion<'_> { future::ProvideRegion::new( self.region() .instrument(tracing::debug_span!("imds_load_region")), @@ -74,7 +74,7 @@ impl ProvideRegion for ImdsRegionProvider { } /// Builder for [`ImdsRegionProvider`] -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { provider_config: Option, imds_client_override: Option, diff --git a/aws/rust-runtime/aws-config/src/json_credentials.rs b/aws/rust-runtime/aws-config/src/json_credentials.rs index fb3cdecc1..8e0650ac7 100644 --- a/aws/rust-runtime/aws-config/src/json_credentials.rs +++ b/aws/rust-runtime/aws-config/src/json_credentials.rs @@ -121,7 +121,7 @@ pub(crate) enum JsonCredentials<'a> { /// Keys are case insensitive. pub(crate) fn parse_json_credentials( credentials_response: &str, -) -> Result { +) -> Result, InvalidJsonCredentials> { let mut code = None; let mut access_key_id = None; let mut secret_access_key = None; diff --git a/aws/rust-runtime/aws-config/src/lib.rs b/aws/rust-runtime/aws-config/src/lib.rs index 5b0655c7a..edb602843 100644 --- a/aws/rust-runtime/aws-config/src/lib.rs +++ b/aws/rust-runtime/aws-config/src/lib.rs @@ -2,7 +2,14 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -#![warn(missing_docs)] + +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + rustdoc::missing_crate_level_docs, + unreachable_pub +)] //! `aws-config` provides implementations of region, credential resolution. //! diff --git a/aws/rust-runtime/aws-config/src/meta/credentials/chain.rs b/aws/rust-runtime/aws-config/src/meta/credentials/chain.rs index 08d83e0ee..229e054f8 100644 --- a/aws/rust-runtime/aws-config/src/meta/credentials/chain.rs +++ b/aws/rust-runtime/aws-config/src/meta/credentials/chain.rs @@ -98,7 +98,7 @@ impl CredentialsProviderChain { } impl ProvideCredentials for CredentialsProviderChain { - fn provide_credentials<'a>(&'a self) -> future::ProvideCredentials + fn provide_credentials<'a>(&'a self) -> future::ProvideCredentials<'_> where Self: 'a, { diff --git a/aws/rust-runtime/aws-config/src/meta/credentials/lazy_caching.rs b/aws/rust-runtime/aws-config/src/meta/credentials/lazy_caching.rs index d3d6280e0..457d6b918 100644 --- a/aws/rust-runtime/aws-config/src/meta/credentials/lazy_caching.rs +++ b/aws/rust-runtime/aws-config/src/meta/credentials/lazy_caching.rs @@ -63,7 +63,7 @@ impl LazyCachingCredentialsProvider { } impl ProvideCredentials for LazyCachingCredentialsProvider { - fn provide_credentials<'a>(&'a self) -> future::ProvideCredentials + fn provide_credentials<'a>(&'a self) -> future::ProvideCredentials<'_> where Self: 'a, { @@ -141,7 +141,7 @@ mod builder { /// })) /// .build(); /// ``` - #[derive(Default)] + #[derive(Debug, Default)] pub struct Builder { sleep: Option>, time_source: Option, diff --git a/aws/rust-runtime/aws-config/src/meta/region.rs b/aws/rust-runtime/aws-config/src/meta/region.rs index 29a712f8c..737f7949f 100644 --- a/aws/rust-runtime/aws-config/src/meta/region.rs +++ b/aws/rust-runtime/aws-config/src/meta/region.rs @@ -76,13 +76,13 @@ impl RegionProviderChain { } impl ProvideRegion for Option { - fn region(&self) -> future::ProvideRegion { + fn region(&self) -> future::ProvideRegion<'_> { future::ProvideRegion::ready(self.clone()) } } impl ProvideRegion for RegionProviderChain { - fn region(&self) -> future::ProvideRegion { + fn region(&self) -> future::ProvideRegion<'_> { future::ProvideRegion::new(RegionProviderChain::region(self)) } } @@ -104,6 +104,7 @@ pub mod future { /// /// - When wrapping an already loaded region, use [`ready`](ProvideRegion::ready). /// - When wrapping an asynchronously loaded region, use [`new`](ProvideRegion::new). + #[derive(Debug)] pub struct ProvideRegion<'a>(NowOrLater, BoxFuture<'a>>); impl<'a> ProvideRegion<'a> { /// A future that wraps the given future @@ -132,29 +133,29 @@ pub mod future { /// a standard provider chain. pub trait ProvideRegion: Send + Sync + Debug { /// Load a region from this provider - fn region(&self) -> future::ProvideRegion; + fn region(&self) -> future::ProvideRegion<'_>; } impl ProvideRegion for Region { - fn region(&self) -> future::ProvideRegion { + fn region(&self) -> future::ProvideRegion<'_> { future::ProvideRegion::ready(Some(self.clone())) } } impl<'a> ProvideRegion for &'a Region { - fn region(&self) -> future::ProvideRegion { + fn region(&self) -> future::ProvideRegion<'_> { future::ProvideRegion::ready(Some((*self).clone())) } } impl ProvideRegion for Box { - fn region(&self) -> future::ProvideRegion { + fn region(&self) -> future::ProvideRegion<'_> { self.as_ref().region() } } impl ProvideRegion for &'static str { - fn region(&self) -> future::ProvideRegion { + fn region(&self) -> future::ProvideRegion<'_> { future::ProvideRegion::ready(Some(Region::new(Cow::Borrowed(*self)))) } } diff --git a/aws/rust-runtime/aws-config/src/profile/app_name.rs b/aws/rust-runtime/aws-config/src/profile/app_name.rs index 7ad3e7772..0b4dfba2d 100644 --- a/aws/rust-runtime/aws-config/src/profile/app_name.rs +++ b/aws/rust-runtime/aws-config/src/profile/app_name.rs @@ -79,7 +79,7 @@ impl ProfileFileAppNameProvider { } /// Builder for [ProfileFileAppNameProvider] -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { config: Option, profile_override: Option, diff --git a/aws/rust-runtime/aws-config/src/profile/credentials.rs b/aws/rust-runtime/aws-config/src/profile/credentials.rs index 78a2d4769..7889bb6e1 100644 --- a/aws/rust-runtime/aws-config/src/profile/credentials.rs +++ b/aws/rust-runtime/aws-config/src/profile/credentials.rs @@ -340,7 +340,7 @@ impl Error for ProfileFileError { } /// Builder for [`ProfileFileCredentialsProvider`] -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { provider_config: Option, profile_override: Option, diff --git a/aws/rust-runtime/aws-config/src/profile/credentials/exec.rs b/aws/rust-runtime/aws-config/src/profile/credentials/exec.rs index b7aa76c84..ea497339c 100644 --- a/aws/rust-runtime/aws-config/src/profile/credentials/exec.rs +++ b/aws/rust-runtime/aws-config/src/profile/credentials/exec.rs @@ -24,20 +24,20 @@ use aws_types::credentials::{self, CredentialsError, ProvideCredentials}; use std::fmt::Debug; #[derive(Debug)] -pub struct AssumeRoleProvider { +pub(super) struct AssumeRoleProvider { role_arn: String, external_id: Option, session_name: Option, } #[derive(Debug)] -pub struct ClientConfiguration { - pub(crate) sts_client: aws_smithy_client::Client, - pub(crate) region: Option, +pub(super) struct ClientConfiguration { + pub(super) sts_client: aws_smithy_client::Client, + pub(super) region: Option, } impl AssumeRoleProvider { - pub async fn credentials( + pub(super) async fn credentials( &self, input_credentials: Credentials, client_config: &ClientConfiguration, @@ -77,19 +77,19 @@ pub(super) struct ProviderChain { } impl ProviderChain { - pub fn base(&self) -> &dyn ProvideCredentials { + pub(crate) fn base(&self) -> &dyn ProvideCredentials { self.base.as_ref() } - pub fn chain(&self) -> &[AssumeRoleProvider] { + pub(crate) fn chain(&self) -> &[AssumeRoleProvider] { self.chain.as_slice() } } impl ProviderChain { - pub fn from_repr( + pub(super) fn from_repr( provider_config: &ProviderConfig, - repr: repr::ProfileChain, + repr: repr::ProfileChain<'_>, factory: &named::NamedProviderFactory, ) -> Result { let base = match repr.base() { @@ -153,7 +153,7 @@ impl ProviderChain { } } -pub mod named { +pub(super) mod named { use std::collections::HashMap; use std::sync::Arc; @@ -161,19 +161,21 @@ pub mod named { use std::borrow::Cow; #[derive(Debug)] - pub struct NamedProviderFactory { + pub(crate) struct NamedProviderFactory { providers: HashMap, Arc>, } - fn lower_cow(mut inp: Cow) -> Cow { - if !inp.chars().all(|c| c.is_ascii_lowercase()) { - inp.to_mut().make_ascii_lowercase(); + fn lower_cow(mut input: Cow<'_, str>) -> Cow<'_, str> { + if !input.chars().all(|c| c.is_ascii_lowercase()) { + input.to_mut().make_ascii_lowercase(); } - inp + input } impl NamedProviderFactory { - pub fn new(providers: HashMap, Arc>) -> Self { + pub(crate) fn new( + providers: HashMap, Arc>, + ) -> Self { let providers = providers .into_iter() .map(|(k, v)| (lower_cow(k), v)) @@ -181,7 +183,7 @@ pub mod named { Self { providers } } - pub fn provider(&self, name: &str) -> Option> { + pub(crate) fn provider(&self, name: &str) -> Option> { self.providers.get(&lower_cow(Cow::Borrowed(name))).cloned() } } diff --git a/aws/rust-runtime/aws-config/src/profile/credentials/repr.rs b/aws/rust-runtime/aws-config/src/profile/credentials/repr.rs index c641ecbb7..98968806e 100644 --- a/aws/rust-runtime/aws-config/src/profile/credentials/repr.rs +++ b/aws/rust-runtime/aws-config/src/profile/credentials/repr.rs @@ -208,38 +208,38 @@ pub(super) fn resolve_chain<'a>( } mod role { - pub const ROLE_ARN: &str = "role_arn"; - pub const EXTERNAL_ID: &str = "external_id"; - pub const SESSION_NAME: &str = "role_session_name"; + pub(super) const ROLE_ARN: &str = "role_arn"; + pub(super) const EXTERNAL_ID: &str = "external_id"; + pub(super) const SESSION_NAME: &str = "role_session_name"; - pub const CREDENTIAL_SOURCE: &str = "credential_source"; - pub const SOURCE_PROFILE: &str = "source_profile"; + pub(super) const CREDENTIAL_SOURCE: &str = "credential_source"; + pub(super) const SOURCE_PROFILE: &str = "source_profile"; } mod sso { - pub const ACCOUNT_ID: &str = "sso_account_id"; - pub const REGION: &str = "sso_region"; - pub const ROLE_NAME: &str = "sso_role_name"; - pub const START_URL: &str = "sso_start_url"; + pub(super) const ACCOUNT_ID: &str = "sso_account_id"; + pub(super) const REGION: &str = "sso_region"; + pub(super) const ROLE_NAME: &str = "sso_role_name"; + pub(super) const START_URL: &str = "sso_start_url"; } mod web_identity_token { - pub const TOKEN_FILE: &str = "web_identity_token_file"; + pub(super) const TOKEN_FILE: &str = "web_identity_token_file"; } mod static_credentials { - pub const AWS_ACCESS_KEY_ID: &str = "aws_access_key_id"; - pub const AWS_SECRET_ACCESS_KEY: &str = "aws_secret_access_key"; - pub const AWS_SESSION_TOKEN: &str = "aws_session_token"; + pub(super) const AWS_ACCESS_KEY_ID: &str = "aws_access_key_id"; + pub(super) const AWS_SECRET_ACCESS_KEY: &str = "aws_secret_access_key"; + pub(super) const AWS_SESSION_TOKEN: &str = "aws_session_token"; } mod credential_process { - pub const CREDENTIAL_PROCESS: &str = "credential_process"; + pub(super) const CREDENTIAL_PROCESS: &str = "credential_process"; } const PROVIDER_NAME: &str = "ProfileFile"; -fn base_provider(profile: &Profile) -> Result { +fn base_provider(profile: &Profile) -> Result, ProfileFileError> { // the profile must define either a `CredentialsSource` or a concrete set of access keys match profile.get(role::CREDENTIAL_SOURCE) { Some(source) => Ok(BaseProvider::NamedSource(source)), @@ -255,7 +255,7 @@ enum NextProfile<'a> { Named(&'a str), } -fn chain_provider(profile: &Profile) -> Result { +fn chain_provider(profile: &Profile) -> Result, ProfileFileError> { let (source_profile, credential_source) = ( profile.get(role::SOURCE_PROFILE), profile.get(role::CREDENTIAL_SOURCE), @@ -282,7 +282,7 @@ fn chain_provider(profile: &Profile) -> Result { } } -fn role_arn_from_profile(profile: &Profile) -> Option { +fn role_arn_from_profile(profile: &Profile) -> Option> { // Web Identity Tokens are root providers, not chained roles if profile.get(web_identity_token::TOKEN_FILE).is_some() { return None; @@ -297,7 +297,7 @@ fn role_arn_from_profile(profile: &Profile) -> Option { }) } -fn sso_from_profile(profile: &Profile) -> Option> { +fn sso_from_profile(profile: &Profile) -> Option, ProfileFileError>> { /* Sample: [profile sample-profile] @@ -334,7 +334,7 @@ fn sso_from_profile(profile: &Profile) -> Option Option> { +) -> Option, ProfileFileError>> { let session_name = profile.get(role::SESSION_NAME); match ( profile.get(role::ROLE_ARN), @@ -401,7 +401,7 @@ fn static_creds_from_profile(profile: &Profile) -> Result Option> { +) -> Option, ProfileFileError>> { profile .get(credential_process::CREDENTIAL_PROCESS) .map(|credential_process| { @@ -467,7 +467,7 @@ mod tests { selected_profile: String, } - fn to_test_output(profile_chain: ProfileChain) -> Vec { + fn to_test_output(profile_chain: ProfileChain<'_>) -> Vec { let mut output = vec![]; match profile_chain.base { BaseProvider::NamedSource(name) => output.push(Provider::NamedSource(name.into())), diff --git a/aws/rust-runtime/aws-config/src/profile/mod.rs b/aws/rust-runtime/aws-config/src/profile/mod.rs index d02e2d8e0..1bb0df6c9 100644 --- a/aws/rust-runtime/aws-config/src/profile/mod.rs +++ b/aws/rust-runtime/aws-config/src/profile/mod.rs @@ -9,8 +9,14 @@ //! see the [`load`](parser::load) function. mod parser; + +// This can't be included in the other `pub use` statement until +// https://github.com/rust-lang/rust/pull/87487 is fixed by upgrading +// to Rust 1.60 +#[doc(inline)] +pub use parser::ProfileParseError; #[doc(inline)] -pub use parser::{load, Profile, ProfileParseError, ProfileSet, Property}; +pub use parser::{load, Profile, ProfileSet, Property}; pub mod app_name; pub mod credentials; diff --git a/aws/rust-runtime/aws-config/src/profile/parser/normalize.rs b/aws/rust-runtime/aws-config/src/profile/parser/normalize.rs index 9738df846..81ad64327 100644 --- a/aws/rust-runtime/aws-config/src/profile/parser/normalize.rs +++ b/aws/rust-runtime/aws-config/src/profile/parser/normalize.rs @@ -20,7 +20,7 @@ struct ProfileName<'a> { } impl ProfileName<'_> { - fn parse(input: &str) -> ProfileName { + fn parse(input: &str) -> ProfileName<'_> { let input = input.trim_matches(WHITESPACE); let (name, has_profile_prefix) = match input.strip_prefix(PROFILE_PREFIX) { // profilefoo isn't considered as having the profile prefix @@ -68,7 +68,7 @@ impl ProfileName<'_> { /// - Profile names are validated (see `validate_profile_name`) /// - A profile named `profile default` takes priority over a profile named `default`. /// - Profiles with identical names are merged -pub fn merge_in(base: &mut ProfileSet, raw_profile_set: RawProfileSet, kind: FileKind) { +pub(super) fn merge_in(base: &mut ProfileSet, raw_profile_set: RawProfileSet<'_>, kind: FileKind) { // parse / validate profile names let validated_profiles = raw_profile_set .into_iter() @@ -212,7 +212,7 @@ mod tests { #[test] #[traced_test] fn ignored_key_generates_warning() { - let mut profile: RawProfileSet = HashMap::new(); + let mut profile: RawProfileSet<'_> = HashMap::new(); profile.insert("default", { let mut out = HashMap::new(); out.insert("invalid key", "value".into()); @@ -233,7 +233,7 @@ mod tests { #[test] #[traced_test] fn invalid_profile_generates_warning() { - let mut profile: RawProfileSet = HashMap::new(); + let mut profile: RawProfileSet<'_> = HashMap::new(); profile.insert("foo", HashMap::new()); merge_in(&mut ProfileSet::empty(), profile, FileKind::Config); assert!(logs_contain("profile `foo` ignored")); diff --git a/aws/rust-runtime/aws-config/src/profile/parser/parse.rs b/aws/rust-runtime/aws-config/src/profile/parser/parse.rs index 58b827a4a..b1d43e58b 100644 --- a/aws/rust-runtime/aws-config/src/profile/parser/parse.rs +++ b/aws/rust-runtime/aws-config/src/profile/parser/parse.rs @@ -19,13 +19,13 @@ use std::error::Error; use std::fmt::{self, Display, Formatter}; /// A set of profiles that still carries a reference to the underlying data -pub type RawProfileSet<'a> = HashMap<&'a str, HashMap<&'a str, Cow<'a, str>>>; +pub(super) type RawProfileSet<'a> = HashMap<&'a str, HashMap<&'a str, Cow<'a, str>>>; /// Characters considered to be whitespace by the spec /// /// Profile parsing is actually quite strict about what is and is not whitespace, so use this instead /// of `.is_whitespace()` / `.trim()` -pub const WHITESPACE: &[char] = &[' ', '\t']; +pub(super) const WHITESPACE: &[char] = &[' ', '\t']; const COMMENT: &[char] = &['#', ';']; /// Location for use during error reporting @@ -104,7 +104,7 @@ enum State<'a> { } /// Parse `file` into a `RawProfileSet` -pub fn parse_profile_file(file: &File) -> Result { +pub(super) fn parse_profile_file(file: &File) -> Result, ProfileParseError> { let mut parser = Parser { data: HashMap::new(), state: State::Starting, diff --git a/aws/rust-runtime/aws-config/src/profile/parser/source.rs b/aws/rust-runtime/aws-config/src/profile/parser/source.rs index f7dcf1205..7ae849ecc 100644 --- a/aws/rust-runtime/aws-config/src/profile/parser/source.rs +++ b/aws/rust-runtime/aws-config/src/profile/parser/source.rs @@ -11,27 +11,27 @@ use std::path::{Component, Path, PathBuf}; use tracing::Instrument; /// In-memory source of profile data -pub struct Source { +pub(super) struct Source { /// Contents and path of ~/.aws/config - pub config_file: File, + pub(super) config_file: File, /// Contents and path of ~/.aws/credentials - pub credentials_file: File, + pub(super) credentials_file: File, /// Profile to use /// /// Overridden via `$AWS_PROFILE`, defaults to `default` - pub profile: Cow<'static, str>, + pub(super) profile: Cow<'static, str>, } /// In-memory configuration file -pub struct File { - pub path: String, - pub contents: String, +pub(super) struct File { + pub(super) path: String, + pub(super) contents: String, } #[derive(Clone, Copy)] -pub enum FileKind { +pub(super) enum FileKind { Config, Credentials, } @@ -53,7 +53,7 @@ impl FileKind { } /// Load a [Source](Source) from a given environment and filesystem. -pub async fn load(proc_env: &os_shim_internal::Env, fs: &os_shim_internal::Fs) -> Source { +pub(super) async fn load(proc_env: &os_shim_internal::Env, fs: &os_shim_internal::Fs) -> Source { let home = home_dir(proc_env, Os::real()); let config = load_config_file(FileKind::Config, &home, fs, proc_env) .instrument(tracing::debug_span!("load_config_file")) diff --git a/aws/rust-runtime/aws-config/src/profile/region.rs b/aws/rust-runtime/aws-config/src/profile/region.rs index e083952b2..e294ed61e 100644 --- a/aws/rust-runtime/aws-config/src/profile/region.rs +++ b/aws/rust-runtime/aws-config/src/profile/region.rs @@ -42,7 +42,7 @@ pub struct ProfileFileRegionProvider { } /// Builder for [ProfileFileRegionProvider] -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { config: Option, profile_override: Option, @@ -149,7 +149,7 @@ fn resolve_profile_chain_for_region( } impl ProvideRegion for ProfileFileRegionProvider { - fn region(&self) -> future::ProvideRegion { + fn region(&self) -> future::ProvideRegion<'_> { future::ProvideRegion::new(self.region()) } } diff --git a/aws/rust-runtime/aws-config/src/profile/retry_config.rs b/aws/rust-runtime/aws-config/src/profile/retry_config.rs index 6f853664c..c876d82f0 100644 --- a/aws/rust-runtime/aws-config/src/profile/retry_config.rs +++ b/aws/rust-runtime/aws-config/src/profile/retry_config.rs @@ -41,7 +41,7 @@ pub struct ProfileFileRetryConfigProvider { } /// Builder for [ProfileFileRetryConfigProvider] -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { config: Option, profile_override: Option, diff --git a/aws/rust-runtime/aws-config/src/profile/timeout_config.rs b/aws/rust-runtime/aws-config/src/profile/timeout_config.rs index 16066db21..f04d58b4f 100644 --- a/aws/rust-runtime/aws-config/src/profile/timeout_config.rs +++ b/aws/rust-runtime/aws-config/src/profile/timeout_config.rs @@ -56,7 +56,7 @@ pub struct ProfileFileTimeoutConfigProvider { } /// Builder for [`ProfileFileTimeoutConfigProvider`] -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { config: Option, profile_override: Option, diff --git a/aws/rust-runtime/aws-config/src/sts/assume_role.rs b/aws/rust-runtime/aws-config/src/sts/assume_role.rs index 36f6d4aa2..60b73d9a3 100644 --- a/aws/rust-runtime/aws-config/src/sts/assume_role.rs +++ b/aws/rust-runtime/aws-config/src/sts/assume_role.rs @@ -69,6 +69,7 @@ impl AssumeRoleProvider { /// A builder for [`AssumeRoleProvider`]. /// /// Construct one through [`AssumeRoleProvider::builder`]. +#[derive(Debug)] pub struct AssumeRoleProviderBuilder { role_arn: String, external_id: Option, @@ -248,7 +249,7 @@ impl Inner { } impl ProvideCredentials for Inner { - fn provide_credentials<'a>(&'a self) -> future::ProvideCredentials + fn provide_credentials<'a>(&'a self) -> future::ProvideCredentials<'_> where Self: 'a, { diff --git a/aws/rust-runtime/aws-config/src/test_case.rs b/aws/rust-runtime/aws-config/src/test_case.rs index 172a3888e..bf5fc8385 100644 --- a/aws/rust-runtime/aws-config/src/test_case.rs +++ b/aws/rust-runtime/aws-config/src/test_case.rs @@ -64,7 +64,7 @@ impl From for Credentials { /// - an `env.json` file containing environment variables /// - an `http-traffic.json` file containing an http traffic log from [`dvr`](aws_smithy_client::dvr) /// - a `test-case.json` file defining the expected output of the test -pub struct TestEnvironment { +pub(crate) struct TestEnvironment { env: Env, fs: Fs, network_traffic: NetworkTraffic, @@ -73,7 +73,7 @@ pub struct TestEnvironment { } /// Connector which expects no traffic -pub fn no_traffic_connector() -> DynConnector { +pub(crate) fn no_traffic_connector() -> DynConnector { DynConnector::new(ReplayingConnection::new(vec![])) } @@ -86,7 +86,7 @@ impl AsyncSleep for InstantSleep { } #[derive(Deserialize)] -pub enum GenericTestResult { +pub(crate) enum GenericTestResult { Ok(T), ErrorContains(String), } @@ -95,7 +95,7 @@ impl GenericTestResult where T: PartialEq + Debug, { - pub fn assert_matches(&self, result: Result, impl Error>) { + pub(crate) fn assert_matches(&self, result: Result, impl Error>) { match (result, &self) { (Ok(actual), GenericTestResult::Ok(expected)) => { assert_eq!(expected, &actual.into(), "incorrect result was returned") @@ -124,14 +124,14 @@ where type TestResult = GenericTestResult; #[derive(Deserialize)] -pub struct Metadata { +pub(crate) struct Metadata { result: TestResult, docs: String, name: String, } impl TestEnvironment { - pub fn from_dir(dir: impl AsRef) -> Result> { + pub(crate) fn from_dir(dir: impl AsRef) -> Result> { let dir = dir.as_ref(); let env = std::fs::read_to_string(dir.join("env.json")) .map_err(|e| format!("failed to load env: {}", e))?; @@ -156,7 +156,7 @@ impl TestEnvironment { }) } - pub async fn provider_config(&self) -> (ReplayingConnection, ProviderConfig) { + pub(crate) async fn provider_config(&self) -> (ReplayingConnection, ProviderConfig) { let connector = ReplayingConnection::new(self.network_traffic.events().clone()); ( connector.clone(), @@ -174,8 +174,10 @@ impl TestEnvironment { /// Record a test case from live (remote) HTTPS traffic /// /// The `default_connector()` from the crate will be used - pub async fn execute_from_live_traffic(&self, make_provider: impl Fn(ProviderConfig) -> F) - where + pub(crate) async fn execute_from_live_traffic( + &self, + make_provider: impl Fn(ProviderConfig) -> F, + ) where F: Future, P: ProvideCredentials, { @@ -200,7 +202,7 @@ impl TestEnvironment { /// /// A connector will be created with the factory, then request traffic will be recorded. /// Response are generated from the existing http-traffic.json. - pub async fn execute_and_update(&self, make_provider: impl Fn(ProviderConfig) -> F) + pub(crate) async fn execute_and_update(&self, make_provider: impl Fn(ProviderConfig) -> F) where F: Future, P: ProvideCredentials, @@ -223,7 +225,7 @@ impl TestEnvironment { } /// Execute a test case. Failures lead to panics. - pub async fn execute(&self, make_provider: impl Fn(ProviderConfig) -> F) + pub(crate) async fn execute(&self, make_provider: impl Fn(ProviderConfig) -> F) where F: Future, P: ProvideCredentials, diff --git a/aws/rust-runtime/aws-config/src/web_identity_token.rs b/aws/rust-runtime/aws-config/src/web_identity_token.rs index da509f941..4d963f7c6 100644 --- a/aws/rust-runtime/aws-config/src/web_identity_token.rs +++ b/aws/rust-runtime/aws-config/src/web_identity_token.rs @@ -124,7 +124,7 @@ impl ProvideCredentials for WebIdentityTokenCredentialsProvider { } impl WebIdentityTokenCredentialsProvider { - fn source(&self) -> Result, CredentialsError> { + fn source(&self) -> Result, CredentialsError> { match &self.source { Source::Env(env) => { let token_file = env.get(ENV_VAR_TOKEN_FILE).map_err(|_| { @@ -170,7 +170,7 @@ impl WebIdentityTokenCredentialsProvider { } /// Builder for [`WebIdentityTokenCredentialsProvider`](WebIdentityTokenCredentialsProvider) -#[derive(Default)] +#[derive(Debug, Default)] pub struct Builder { source: Option, config: Option, -- GitLab