Skip to content

Commit

Permalink
disable unexpected logs from azure identity and fix tips message rela…
Browse files Browse the repository at this point in the history
…ted to MFA. #2270
  • Loading branch information
wangmingliang-ms committed Apr 9, 2023
1 parent 40e01c8 commit a2ce1b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,16 @@ private static AuthConfiguration convertToAuthConfiguration(MavenAuthConfigurati
return authConfiguration;
}

/**
* disable unexpected logs from azure identity
*/
public static void disableIdentityLogs() {
// add breakpoint on `org.slf4j.Logger.error` to track the logged errors.
putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.azure.identity", "off");
putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.azure.identity.implementation", "off");
putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.microsoft.aad.msal4j", "off");
putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.azure.core.http.policy", "off");
putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.azure.core.implementation", "off");
putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.microsoft.aad.adal4j", "off");
putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.azure.core.credential", "off");
putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.microsoft.aad.msal4jextensions", "off");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.azure.resourcemanager.resources.models.Tenant;
import com.microsoft.azure.toolkit.lib.Azure;
import com.microsoft.azure.toolkit.lib.account.IAccount;
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
import com.microsoft.azure.toolkit.lib.common.cache.CacheEvict;
import com.microsoft.azure.toolkit.lib.common.cache.Preloader;
import com.microsoft.azure.toolkit.lib.common.event.AzureEventBus;
Expand Down Expand Up @@ -112,7 +113,9 @@ protected Optional<AccessToken> getManagementToken() {
final String[] scopes = ScopeUtil.resourceToScopes(this.getEnvironment().getManagementEndpoint());
final TokenRequestContext request = new TokenRequestContext().addScopes(scopes);
try {
return this.buildDefaultTokenCredential().getToken(request).blockOptional();
return this.buildDefaultTokenCredential().getToken(request)
.onErrorResume(Exception.class, t -> Mono.empty())
.blockOptional();
} catch (Throwable t) {
return Optional.empty();
}
Expand Down Expand Up @@ -168,8 +171,10 @@ private List<Subscription> loadSubscriptions(String tenantId) {
final AzureProfile profile = new AzureProfile(tenantId, null, this.getEnvironment());
final ResourceManager.Authenticated client = configureAzure().authenticate(credential, profile);
final List<Subscription> subscriptions = client.subscriptions().listAsync().onErrorResume(ex -> {
AzureMessager.getMessager().warning(String.format("Cannot get subscriptions for tenant %s " +
", please verify you have proper permissions over this tenant, detailed error: %s", tenantId, ex.getMessage()));
AzureMessager.getMessager().warning(AzureString.format(
"Failed to get subscriptions for tenant %s, please confirm you have sufficient permissions." +
" Use %s to explicitly login to a tenant if it requires Multi-Factor Authentication (MFA)." +
" Message: %s", tenantId, "-Dauth.tenant=TENANT_ID", ex.getMessage()));
return Flux.fromIterable(new ArrayList<>());
}).map(Subscription::new)
.collect(Collectors.toList()).flatMapIterable(s -> s).collectList().block();
Expand Down

0 comments on commit a2ce1b6

Please sign in to comment.