Skip to content

Commit b3fbae1

Browse files
committed
Revert "trait implementation"
1 parent 78bcbc3 commit b3fbae1

File tree

5 files changed

+24
-80
lines changed

5 files changed

+24
-80
lines changed

sdk/identity/azure_identity/src/azure_pipelines_credential.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl fmt::Display for ErrorHeaders {
226226
#[cfg(test)]
227227
mod tests {
228228
use super::*;
229-
use crate::{env::Env, TroubleshootingGuide, TSG_LINK_ERROR_TEXT};
229+
use crate::{env::Env, TSG_LINK_ERROR_TEXT};
230230
use azure_core::{
231231
http::{BufResponse, ClientOptions, Transport},
232232
Bytes,
@@ -300,10 +300,8 @@ mod tests {
300300
err.to_string().contains("bar"),
301301
));
302302
assert!(
303-
err.to_string().contains(&format!(
304-
"{TSG_LINK_ERROR_TEXT}{}",
305-
AzurePipelinesCredential::FRAGMENT
306-
)),
303+
err.to_string()
304+
.contains(&format!("{TSG_LINK_ERROR_TEXT}#apc")),
307305
"expected error to contain a link to the troubleshooting guide, got '{err}'",
308306
);
309307
}

sdk/identity/azure_identity/src/client_secret_credential.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl TokenCredential for ClientSecretCredential {
172172
#[cfg(test)]
173173
mod tests {
174174
use super::*;
175-
use crate::{tests::*, TroubleshootingGuide, TSG_LINK_ERROR_TEXT};
175+
use crate::{tests::*, TSG_LINK_ERROR_TEXT};
176176
use azure_core::{
177177
authority_hosts::AZURE_PUBLIC_CLOUD,
178178
http::{headers::Headers, BufResponse, StatusCode, Transport},
@@ -237,10 +237,8 @@ mod tests {
237237
err
238238
);
239239
assert!(
240-
err.to_string().contains(&format!(
241-
"{TSG_LINK_ERROR_TEXT}{}",
242-
ClientSecretCredential::FRAGMENT
243-
)),
240+
err.to_string()
241+
.contains(&format!("{TSG_LINK_ERROR_TEXT}#client-secret")),
244242
"expected error to contain a link to the troubleshooting guide, got '{err}'",
245243
);
246244
}

sdk/identity/azure_identity/src/lib.rs

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -115,72 +115,24 @@ fn get_authority_host(env: Option<Env>, option: Option<String>) -> Result<Url> {
115115
const TSG_LINK_ERROR_TEXT: &str =
116116
". To troubleshoot, visit https://aka.ms/azsdk/rust/identity/troubleshoot";
117117

118-
/// A troubleshooting guide entry.
119-
#[doc(hidden)]
120-
pub trait TroubleshootingGuide: private::Sealed {
121-
/// The URL fragment (leading '#' and an anchor) for this type's entry in the troubleshooting guide.
122-
const FRAGMENT: &'static str;
123-
}
124-
125-
#[cfg(not(target_arch = "wasm32"))]
126-
impl TroubleshootingGuide for AzureCliCredential {
127-
const FRAGMENT: &'static str = "#azure-cli";
128-
}
129-
130-
#[cfg(not(target_arch = "wasm32"))]
131-
impl TroubleshootingGuide for AzureDeveloperCliCredential {
132-
const FRAGMENT: &'static str = "#azd";
133-
}
134-
135-
impl TroubleshootingGuide for AzurePipelinesCredential {
136-
const FRAGMENT: &'static str = "#apc";
137-
}
138-
139-
#[cfg(feature = "client_certificate")]
140-
impl TroubleshootingGuide for ClientCertificateCredential {
141-
const FRAGMENT: &'static str = "#client-cert";
142-
}
143-
144-
impl TroubleshootingGuide for ClientSecretCredential {
145-
const FRAGMENT: &'static str = "#client-secret";
146-
}
147-
148-
impl TroubleshootingGuide for ManagedIdentityCredential {
149-
const FRAGMENT: &'static str = "#managed-id";
150-
}
151-
152-
impl TroubleshootingGuide for WorkloadIdentityCredential {
153-
const FRAGMENT: &'static str = "#workload";
154-
}
155-
156-
mod private {
157-
pub trait Sealed {}
158-
#[cfg(not(target_arch = "wasm32"))]
159-
impl Sealed for super::AzureCliCredential {}
160-
#[cfg(not(target_arch = "wasm32"))]
161-
impl Sealed for super::AzureDeveloperCliCredential {}
162-
impl Sealed for super::AzurePipelinesCredential {}
163-
#[cfg(feature = "client_certificate")]
164-
impl Sealed for super::ClientCertificateCredential {}
165-
impl Sealed for super::ClientSecretCredential {}
166-
impl Sealed for super::ManagedIdentityCredential {}
167-
impl Sealed for super::WorkloadIdentityCredential {}
168-
}
169-
170118
/// Map an error from a credential's get_token() method to an ErrorKind::Credential error, appending
171119
/// a link to the troubleshooting guide entry for that credential, if it has one.
172120
///
173121
/// TODO: decide whether to map to ErrorKind::Credential here (https://github.com/Azure/azure-sdk-for-rust/issues/3127)
174-
fn authentication_error<T: TroubleshootingGuide + 'static>(
175-
e: azure_core::Error,
176-
) -> azure_core::Error {
122+
fn authentication_error<T: 'static>(e: azure_core::Error) -> azure_core::Error {
177123
azure_core::Error::with_message_fn(e.kind().clone(), || {
178124
let type_name = std::any::type_name::<T>();
179-
let short_name = type_name.rsplit("::").next().unwrap_or(type_name);
180-
let link = if T::FRAGMENT.is_empty() {
181-
String::new()
182-
} else {
183-
format!("{TSG_LINK_ERROR_TEXT}{}", T::FRAGMENT)
125+
let short_name = type_name.rsplit("::").next().unwrap_or(type_name); // cspell:ignore rsplit
126+
let link = match short_name {
127+
"AzureCliCredential" => format!("{TSG_LINK_ERROR_TEXT}#azure-cli"),
128+
"AzureDeveloperCliCredential" => format!("{TSG_LINK_ERROR_TEXT}#azd"),
129+
"AzurePipelinesCredential" => format!("{TSG_LINK_ERROR_TEXT}#apc"),
130+
#[cfg(feature = "client_certificate")]
131+
"ClientCertificateCredential" => format!("{TSG_LINK_ERROR_TEXT}#client-cert"),
132+
"ClientSecretCredential" => format!("{TSG_LINK_ERROR_TEXT}#client-secret"),
133+
"ManagedIdentityCredential" => format!("{TSG_LINK_ERROR_TEXT}#managed-id"),
134+
"WorkloadIdentityCredential" => format!("{TSG_LINK_ERROR_TEXT}#workload"),
135+
_ => "".to_string(),
184136
};
185137

186138
format!("{short_name} authentication failed: {e}{link}")

sdk/identity/azure_identity/src/managed_identity_credential.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ mod tests {
168168
use crate::{
169169
env::Env,
170170
tests::{LIVE_TEST_RESOURCE, LIVE_TEST_SCOPES},
171-
TroubleshootingGuide, TSG_LINK_ERROR_TEXT,
171+
TSG_LINK_ERROR_TEXT,
172172
};
173173
use azure_core::http::headers::Headers;
174174
use azure_core::http::{BufResponse, Method, Request, StatusCode, Transport, Url};
@@ -462,10 +462,8 @@ mod tests {
462462
.to_string()
463463
.contains("the requested identity has not been assigned to this resource"));
464464
assert!(
465-
err.to_string().contains(&format!(
466-
"{TSG_LINK_ERROR_TEXT}{}",
467-
ManagedIdentityCredential::FRAGMENT
468-
)),
465+
err.to_string()
466+
.contains(&format!("{TSG_LINK_ERROR_TEXT}#managed-id")),
469467
"expected error to contain a link to the troubleshooting guide, got '{err}'",
470468
);
471469
}

sdk/identity/azure_identity/src/workload_identity_credential.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ mod tests {
191191
client_assertion_credential::tests::{is_valid_request, FAKE_ASSERTION},
192192
env::Env,
193193
tests::*,
194-
TroubleshootingGuide, TSG_LINK_ERROR_TEXT,
194+
TSG_LINK_ERROR_TEXT,
195195
};
196196
use azure_core::{
197197
http::{
@@ -316,10 +316,8 @@ mod tests {
316316
));
317317
assert!(err.to_string().contains(description));
318318
assert!(
319-
err.to_string().contains(&format!(
320-
"{TSG_LINK_ERROR_TEXT}{}",
321-
WorkloadIdentityCredential::FRAGMENT
322-
)),
319+
err.to_string()
320+
.contains(&format!("{TSG_LINK_ERROR_TEXT}#workload")),
323321
"expected error to contain a link to the troubleshooting guide, got '{err}'",
324322
);
325323
}

0 commit comments

Comments
 (0)