Skip to content

Commit

Permalink
opt out of cli for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
cataggar committed Jan 10, 2024
1 parent 4fd16c4 commit 5ea58fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions sdk/identity/src/token_credentials/default_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl DefaultAzureCredentialBuilder {
VirtualMachineManagedIdentityCredential::new(self.options.clone()),
));
}
#[cfg(not(target_arch = "wasm32"))]
DefaultAzureCredentialType::AzureCli => {
if let Ok(credential) = AzureCliCredential::create() {
sources.push(DefaultAzureCredentialEnum::AzureCli(credential));
Expand Down Expand Up @@ -165,6 +166,7 @@ enum DefaultAzureCredentialType {
Environment,
AppService,
VirtualMachine,
#[cfg(not(target_arch = "wasm32"))]
AzureCli,
}

Expand Down
16 changes: 11 additions & 5 deletions sdk/identity/src/token_credentials/specific_azure_credential.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
use super::options;
use std::sync::Arc;

#[cfg(not(target_arch = "wasm32"))]
use crate::AzureCliCredential;
#[cfg(feature = "client_certificate")]
use crate::ClientCertificateCredential;
use crate::{
AppServiceManagedIdentityCredential, AzureCliCredential, ClientSecretCredential,
EnvironmentCredential, TokenCredentialOptions, VirtualMachineManagedIdentityCredential,
WorkloadIdentityCredential,
AppServiceManagedIdentityCredential, ClientSecretCredential, EnvironmentCredential,
TokenCredentialOptions, VirtualMachineManagedIdentityCredential, WorkloadIdentityCredential,
};
use azure_core::{
auth::{AccessToken, TokenCredential},
error::{ErrorKind, ResultExt},
Error,
};
use std::sync::Arc;

pub const AZURE_CREDENTIAL_TYPE: &str = "AZURE_CREDENTIAL_TYPE";

pub mod azure_credential_types {
pub const ENVIRONMENT: &str = "environment";
#[cfg(not(target_arch = "wasm32"))]
pub const AZURE_CLI: &str = "azurecli";
pub const VIRTUAL_MACHINE: &str = "virtualmachine";
pub const APP_SERVICE: &str = "appservice";
Expand Down Expand Up @@ -57,6 +58,7 @@ pub fn create_specific_credential() -> azure_core::Result<Arc<dyn TokenCredentia
#[derive(Debug)]
pub enum SpecificAzureCredentialEnum {
Environment(EnvironmentCredential),
#[cfg(not(target_arch = "wasm32"))]
AzureCli(AzureCliCredential),
VirtualMachine(VirtualMachineManagedIdentityCredential),
AppService(AppServiceManagedIdentityCredential),
Expand All @@ -74,6 +76,7 @@ impl TokenCredential for SpecificAzureCredentialEnum {
SpecificAzureCredentialEnum::Environment(credential) => {
credential.get_token(scopes).await
}
#[cfg(not(target_arch = "wasm32"))]
SpecificAzureCredentialEnum::AzureCli(credential) => credential.get_token(scopes).await,
SpecificAzureCredentialEnum::VirtualMachine(credential) => {
credential.get_token(scopes).await
Expand All @@ -97,6 +100,7 @@ impl TokenCredential for SpecificAzureCredentialEnum {
async fn clear_cache(&self) -> azure_core::Result<()> {
match self {
SpecificAzureCredentialEnum::Environment(credential) => credential.clear_cache().await,
#[cfg(not(target_arch = "wasm32"))]
SpecificAzureCredentialEnum::AzureCli(credential) => credential.clear_cache().await,
SpecificAzureCredentialEnum::VirtualMachine(credential) => {
credential.clear_cache().await
Expand Down Expand Up @@ -145,6 +149,7 @@ impl SpecificAzureCredential {
azure_credential_types::VIRTUAL_MACHINE => SpecificAzureCredentialEnum::VirtualMachine(
VirtualMachineManagedIdentityCredential::new(options),
),
#[cfg(not(target_arch = "wasm32"))]
azure_credential_types::AZURE_CLI => AzureCliCredential::create()
.map(SpecificAzureCredentialEnum::AzureCli)
.with_context(ErrorKind::Credential, || {
Expand Down Expand Up @@ -238,6 +243,7 @@ mod tests {

/// test AZURE_CREDENTIAL_TYPE of "azurecli"
#[test]
#[cfg(not(target_arch = "wasm32"))]
fn test_azure_cli() -> azure_core::Result<()> {
let credential = SpecificAzureCredential::create(test_options(
&[("AZURE_CREDENTIAL_TYPE", "azurecli")][..],
Expand Down

0 comments on commit 5ea58fe

Please sign in to comment.