use of com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException in project azure-maven-plugins by microsoft.
the class ConfigMojo method chooseExistingWebappForConfiguration.
private WebAppConfiguration chooseExistingWebappForConfiguration() throws AzureAuthFailureException {
try {
final AzureAppService az = getOrCreateAzureAppServiceClient();
if (Objects.isNull(az)) {
return null;
}
// get user selected sub id to persistent it in pom.xml
this.subscriptionId = az.getDefaultSubscription().getId();
// load configuration to detecting java or docker
Log.info(LONG_LOADING_HINT);
final List<WebAppOption> webAppOptionList = az.webapps().stream().map(WebAppOption::new).sorted().collect(Collectors.toList());
// check empty: first time
if (webAppOptionList.isEmpty()) {
Log.warn(NO_JAVA_WEB_APPS);
return null;
}
final boolean isContainer = !Utils.isJarPackagingProject(this.project.getPackaging());
final boolean isDockerOnly = Utils.isPomPackagingProject(this.project.getPackaging());
final List<WebAppOption> javaOrDockerWebapps = webAppOptionList.stream().filter(app -> app.isJavaWebApp() || app.isDockerWebapp()).filter(app -> checkWebAppVisible(isContainer, isDockerOnly, app.isJavaSE(), app.isDockerWebapp())).sorted().collect(Collectors.toList());
final TextIO textIO = TextIoFactory.getTextIO();
final WebAppOption selectedApp = selectAzureWebApp(textIO, javaOrDockerWebapps, getWebAppTypeByPackaging(this.project.getPackaging()), az.getDefaultSubscription());
if (selectedApp == null || selectedApp.isCreateNew()) {
return null;
}
final IWebApp webapp = az.webapp(selectedApp.getId());
final WebAppConfiguration.WebAppConfigurationBuilder<?, ?> builder = WebAppConfiguration.builder();
if (!AppServiceUtils.isDockerAppService(webapp)) {
builder.resources(Deployment.getDefaultDeploymentConfiguration(getProject().getPackaging()).getResources());
}
return getConfigurationFromExisting(webapp, builder);
} catch (AzureToolkitAuthenticationException ex) {
// if is valid for config goal to have error in authentication
getLog().warn(String.format("Cannot authenticate due to error: %s, select existing webapp is skipped.", ex.getMessage()));
return null;
}
}
use of com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException in project azure-maven-plugins by microsoft.
the class AbstractAzureMojo method findFirstAvailableAccount.
private static Mono<Account> findFirstAvailableAccount() {
final List<Account> accounts = Azure.az(AzureAccount.class).accounts();
if (accounts.isEmpty()) {
return Mono.error(new AzureToolkitAuthenticationException("there are no subscriptions available."));
}
Mono<Account> current = checkAccountAvailable(accounts.get(0));
for (int i = 1; i < accounts.size(); i++) {
final Account ac = accounts.get(i);
current = current.onErrorResume(e -> checkAccountAvailable(ac));
}
return current;
}
use of com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException in project azure-gradle-plugins by microsoft.
the class GradleAuthHelper method findFirstAvailableAccount.
private static Mono<Account> findFirstAvailableAccount() {
final List<Account> accounts = Azure.az(AzureAccount.class).accounts();
if (accounts.isEmpty()) {
return Mono.error(new AzureToolkitAuthenticationException("There are no accounts available."));
}
Mono<Account> current = checkAccountAvailable(accounts.get(0));
for (int i = 1; i < accounts.size(); i++) {
final Account ac = accounts.get(i);
current = current.onErrorResume(e -> checkAccountAvailable(ac));
}
return current;
}
Aggregations