use of com.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException in project azure-maven-plugins by microsoft.
the class ConfigMojo method doExecute.
@Override
protected void doExecute() throws AzureExecutionException {
if (!settings.isInteractiveMode()) {
throw new UnsupportedOperationException("The goal 'config' must be run at interactive mode.");
}
if (!MavenConfigUtils.isPomPackaging(this.project) && !MavenConfigUtils.isJarPackaging(this.project)) {
throw new UnsupportedOperationException(String.format("The project (%s) with packaging %s is not supported for azure spring cloud service.", this.project.getName(), this.project.getPackaging()));
}
if (isProjectConfigured(this.project)) {
getLog().warn(String.format("Project (%s) is already configured and won't be affected by this command.", this.project.getName()));
return;
}
appSettings = new AppRawConfig();
deploymentSettings = new AppDeploymentRawConfig();
parentMode = MavenConfigUtils.isPomPackaging(this.project);
if (parentMode && advancedOptions) {
throw new UnsupportedOperationException("The \"advancedOptions\" mode is not supported at parent folder.");
}
final ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
try {
this.wrapper = new ConfigurationPrompter(expressionEvaluator, getLog());
this.wrapper.initialize();
this.wrapper.putCommonVariable("project", this.project);
selectProjects();
if (targetProjects == null || targetProjects.isEmpty()) {
// no need to proceed when there are no projects need to be configured
return;
}
// select subscription in spring cloud -> config is different from other goals since it is prompted after select project.
// set up account and select subscription here
getAzureAccount();
promptAndSelectSubscription();
selectAppCluster();
configCommon();
confirmAndSave();
} catch (IOException | InvalidConfigurationException | UnsupportedOperationException | MavenDecryptException | LoginFailureException e) {
throw new AzureExecutionException(e.getMessage());
} finally {
if (this.wrapper != null) {
try {
this.wrapper.close();
} catch (IOException e) {
// ignore at final step
}
}
}
}
use of com.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException 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