use of com.microsoft.azure.toolkit.lib.auth.core.serviceprincipal.ServicePrincipalAccount in project azure-maven-plugins by microsoft.
the class AzureAccount method loginAsync.
public Mono<Account> loginAsync(@Nonnull AuthConfiguration auth, boolean enablePersistence) {
Objects.requireNonNull(auth, "Auth configuration is required for login.");
Objects.requireNonNull(auth.getType(), "Auth type is required for login.");
Preconditions.checkArgument(auth.getType() != AuthType.AUTO, "Auth type 'auto' is illegal for login.");
if (auth.getEnvironment() != null) {
Azure.az(AzureCloud.class).set(auth.getEnvironment());
}
AuthType type = auth.getType();
final Account targetAccount;
if (auth.getType() == AuthType.SERVICE_PRINCIPAL) {
targetAccount = new ServicePrincipalAccount(auth);
} else {
Map<AuthType, Supplier<Account>> accountByType = buildAccountMap();
if (!accountByType.containsKey(type)) {
return Mono.error(new LoginFailureException(String.format("Unsupported auth type '%s', supported values are: %s.", type, accountByType.keySet().stream().map(Object::toString).map(StringUtils::lowerCase).collect(Collectors.joining(", ")))));
}
targetAccount = accountByType.get(type).get();
}
return loginAsync(targetAccount, enablePersistence);
}
Aggregations