Skip to content

Commit

Permalink
Incorporate feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti committed Nov 15, 2022
1 parent f0f6f08 commit 794b40d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
29 changes: 23 additions & 6 deletions aws/rust-runtime/aws-config/src/imds/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,29 @@ use crate::imds::client::{ImdsError, LazyClient};
use crate::json_credentials::{parse_json_credentials, JsonCredentials, RefreshableCredentials};
use crate::provider_config::ProviderConfig;
use aws_smithy_client::SdkError;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::credentials::{future, CredentialsError, ProvideCredentials};
use aws_types::os_shim_internal::Env;
use aws_types::{credentials, Credentials};
use std::borrow::Cow;
use std::error::Error as StdError;
use std::fmt;

#[derive(Debug)]
struct ImdsCommunicationError {
source: Box<dyn StdError + Send + Sync + 'static>,
}

impl fmt::Display for ImdsCommunicationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "could not communicate with IMDS")
}
}

impl StdError for ImdsCommunicationError {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
Some(self.source.as_ref())
}
}

/// IMDSv2 Credentials Provider
///
Expand Down Expand Up @@ -138,11 +156,10 @@ impl ImdsCredentialsProvider {
);
Err(CredentialsError::not_loaded("received 404 from IMDS"))
}
Err(ImdsError::FailedToLoadToken(ref err @ SdkError::DispatchFailure(_))) => {
Err(CredentialsError::not_loaded(format!(
"could not communicate with IMDS: {}",
DisplayErrorContext(&err)
)))
Err(ImdsError::FailedToLoadToken(err @ SdkError::DispatchFailure(_))) => {
Err(CredentialsError::not_loaded(ImdsCommunicationError {
source: err.into(),
}))
}
Err(other) => Err(CredentialsError::provider_error(other)),
}
Expand Down
8 changes: 6 additions & 2 deletions aws/rust-runtime/aws-sig-auth/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ impl Display for SigningStageError {

impl Error for SigningStageError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
use SigningStageErrorKind as ErrorKind;
match &self.kind {
SigningStageErrorKind::SigningFailure(err) => Some(err),
_ => None,
ErrorKind::SigningFailure(err) => Some(err),
ErrorKind::MissingCredentials
| ErrorKind::MissingSigningRegion
| ErrorKind::MissingSigningService
| ErrorKind::MissingSigningConfig => None,
}
}
}
Expand Down

0 comments on commit 794b40d

Please sign in to comment.