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

include source stack in aggregated errors in DefaultAzureCredential #1546

Merged
Merged
Changes from all commits
Commits
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
41 changes: 20 additions & 21 deletions sdk/identity/src/token_credentials/default_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,23 @@ pub enum DefaultAzureCredentialEnum {
impl TokenCredential for DefaultAzureCredentialEnum {
async fn get_token(&self, scopes: &[&str]) -> azure_core::Result<AccessToken> {
match self {
DefaultAzureCredentialEnum::Environment(credential) => {
credential.get_token(scopes).await.context(
ErrorKind::Credential,
"error getting environment credential",
)
}
DefaultAzureCredentialEnum::Environment(credential) => credential
.get_token(scopes)
.await
.context(ErrorKind::Credential, "environment credential"),
DefaultAzureCredentialEnum::ManagedIdentity(credential) => {
// IMSD timeout is only limited to 1 second when used in DefaultAzureCredential
credential
.get_token(scopes)
.timeout(Duration::from_secs(1))
.await
.context(
ErrorKind::Credential,
"getting managed identity credential timed out",
)?
.context(
ErrorKind::Credential,
"error getting managed identity credential",
)
}
DefaultAzureCredentialEnum::AzureCli(credential) => {
credential.get_token(scopes).await.context(
ErrorKind::Credential,
"error getting token credential from Azure CLI",
)
.context(ErrorKind::Credential, "IMDS timeout")?
.context(ErrorKind::Credential, "IMDS")
}
DefaultAzureCredentialEnum::AzureCli(credential) => credential
.get_token(scopes)
.await
.context(ErrorKind::Credential, "az-cli"),
}
}

Expand Down Expand Up @@ -205,9 +195,18 @@ impl TokenCredential for DefaultAzureCredential {
}

fn format_aggregate_error(errors: &[Error]) -> String {
use std::error::Error;
errors
.iter()
.map(ToString::to_string)
.map(|e| {
let mut current: Option<&dyn Error> = Some(e);
let mut stack = vec![];
while let Some(err) = current.take() {
stack.push(err.to_string());
current = err.source();
}
stack.join(" - ")
})
.collect::<Vec<String>>()
.join("\n")
}
Expand Down