Skip to content

Commit adde1c8

Browse files
committed
Revert "trait implementation"
1 parent b252ec2 commit adde1c8

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
@@ -167,7 +167,7 @@ impl TokenCredential for ClientSecretCredential {
167167
#[cfg(test)]
168168
mod tests {
169169
use super::*;
170-
use crate::{tests::*, TroubleshootingGuide, TSG_LINK_ERROR_TEXT};
170+
use crate::{tests::*, TSG_LINK_ERROR_TEXT};
171171
use azure_core::{
172172
http::{headers::Headers, BufResponse, StatusCode, Transport},
173173
Bytes, Result,
@@ -257,10 +257,8 @@ mod tests {
257257
err
258258
);
259259
assert!(
260-
err.to_string().contains(&format!(
261-
"{TSG_LINK_ERROR_TEXT}{}",
262-
ClientSecretCredential::FRAGMENT
263-
)),
260+
err.to_string()
261+
.contains(&format!("{TSG_LINK_ERROR_TEXT}#client-secret")),
264262
"expected error to contain a link to the troubleshooting guide, got '{err}'",
265263
);
266264
}

sdk/identity/azure_identity/src/lib.rs

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -136,72 +136,24 @@ fn get_authority_host(env: Option<Env>, cloud: Option<&CloudConfiguration>) -> R
136136
const TSG_LINK_ERROR_TEXT: &str =
137137
". To troubleshoot, visit https://aka.ms/azsdk/rust/identity/troubleshoot";
138138

139-
/// A troubleshooting guide entry.
140-
#[doc(hidden)]
141-
pub trait TroubleshootingGuide: private::Sealed {
142-
/// The URL fragment (leading '#' and an anchor) for this type's entry in the troubleshooting guide.
143-
const FRAGMENT: &'static str;
144-
}
145-
146-
#[cfg(not(target_arch = "wasm32"))]
147-
impl TroubleshootingGuide for AzureCliCredential {
148-
const FRAGMENT: &'static str = "#azure-cli";
149-
}
150-
151-
#[cfg(not(target_arch = "wasm32"))]
152-
impl TroubleshootingGuide for AzureDeveloperCliCredential {
153-
const FRAGMENT: &'static str = "#azd";
154-
}
155-
156-
impl TroubleshootingGuide for AzurePipelinesCredential {
157-
const FRAGMENT: &'static str = "#apc";
158-
}
159-
160-
#[cfg(feature = "client_certificate")]
161-
impl TroubleshootingGuide for ClientCertificateCredential {
162-
const FRAGMENT: &'static str = "#client-cert";
163-
}
164-
165-
impl TroubleshootingGuide for ClientSecretCredential {
166-
const FRAGMENT: &'static str = "#client-secret";
167-
}
168-
169-
impl TroubleshootingGuide for ManagedIdentityCredential {
170-
const FRAGMENT: &'static str = "#managed-id";
171-
}
172-
173-
impl TroubleshootingGuide for WorkloadIdentityCredential {
174-
const FRAGMENT: &'static str = "#workload";
175-
}
176-
177-
mod private {
178-
pub trait Sealed {}
179-
#[cfg(not(target_arch = "wasm32"))]
180-
impl Sealed for super::AzureCliCredential {}
181-
#[cfg(not(target_arch = "wasm32"))]
182-
impl Sealed for super::AzureDeveloperCliCredential {}
183-
impl Sealed for super::AzurePipelinesCredential {}
184-
#[cfg(feature = "client_certificate")]
185-
impl Sealed for super::ClientCertificateCredential {}
186-
impl Sealed for super::ClientSecretCredential {}
187-
impl Sealed for super::ManagedIdentityCredential {}
188-
impl Sealed for super::WorkloadIdentityCredential {}
189-
}
190-
191139
/// Map an error from a credential's get_token() method to an ErrorKind::Credential error, appending
192140
/// a link to the troubleshooting guide entry for that credential, if it has one.
193141
///
194142
/// TODO: decide whether to map to ErrorKind::Credential here (https://github.com/Azure/azure-sdk-for-rust/issues/3127)
195-
fn authentication_error<T: TroubleshootingGuide + 'static>(
196-
e: azure_core::Error,
197-
) -> azure_core::Error {
143+
fn authentication_error<T: 'static>(e: azure_core::Error) -> azure_core::Error {
198144
azure_core::Error::with_message_fn(e.kind().clone(), || {
199145
let type_name = std::any::type_name::<T>();
200-
let short_name = type_name.rsplit("::").next().unwrap_or(type_name);
201-
let link = if T::FRAGMENT.is_empty() {
202-
String::new()
203-
} else {
204-
format!("{TSG_LINK_ERROR_TEXT}{}", T::FRAGMENT)
146+
let short_name = type_name.rsplit("::").next().unwrap_or(type_name); // cspell:ignore rsplit
147+
let link = match short_name {
148+
"AzureCliCredential" => format!("{TSG_LINK_ERROR_TEXT}#azure-cli"),
149+
"AzureDeveloperCliCredential" => format!("{TSG_LINK_ERROR_TEXT}#azd"),
150+
"AzurePipelinesCredential" => format!("{TSG_LINK_ERROR_TEXT}#apc"),
151+
#[cfg(feature = "client_certificate")]
152+
"ClientCertificateCredential" => format!("{TSG_LINK_ERROR_TEXT}#client-cert"),
153+
"ClientSecretCredential" => format!("{TSG_LINK_ERROR_TEXT}#client-secret"),
154+
"ManagedIdentityCredential" => format!("{TSG_LINK_ERROR_TEXT}#managed-id"),
155+
"WorkloadIdentityCredential" => format!("{TSG_LINK_ERROR_TEXT}#workload"),
156+
_ => "".to_string(),
205157
};
206158

207159
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::{
@@ -318,10 +318,8 @@ mod tests {
318318
));
319319
assert!(err.to_string().contains(description));
320320
assert!(
321-
err.to_string().contains(&format!(
322-
"{TSG_LINK_ERROR_TEXT}{}",
323-
WorkloadIdentityCredential::FRAGMENT
324-
)),
321+
err.to_string()
322+
.contains(&format!("{TSG_LINK_ERROR_TEXT}#workload")),
325323
"expected error to contain a link to the troubleshooting guide, got '{err}'",
326324
);
327325
}

0 commit comments

Comments
 (0)