Search in sources :

Example 11 with AzureToolkitAuthenticationException

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;
    }
}
Also used : Azure(com.microsoft.azure.toolkit.lib.Azure) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) Arrays(java.util.Arrays) TextIO(org.beryx.textio.TextIO) AppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig) Utils.findStringInCollectionIgnoreCase(com.microsoft.azure.maven.webapp.utils.Utils.findStringInCollectionIgnoreCase) StringUtils(org.apache.commons.lang3.StringUtils) MavenConfigUtils(com.microsoft.azure.maven.utils.MavenConfigUtils) WebAppPomHandler(com.microsoft.azure.maven.webapp.handlers.WebAppPomHandler) MavenPluginQueryer(com.microsoft.azure.maven.queryer.MavenPluginQueryer) Map(java.util.Map) WebContainer(com.microsoft.azure.toolkit.lib.appservice.model.WebContainer) SchemaVersion(com.microsoft.azure.maven.webapp.configuration.SchemaVersion) AppServiceUtils(com.microsoft.azure.toolkit.lib.legacy.appservice.AppServiceUtils) Runtime(com.microsoft.azure.toolkit.lib.appservice.model.Runtime) JavaVersion(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) AzureAuthFailureException(com.microsoft.azure.maven.auth.AzureAuthFailureException) AzureToolkitAuthenticationException(com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException) List(java.util.List) Stream(java.util.stream.Stream) TextUtils(com.microsoft.azure.toolkit.lib.common.utils.TextUtils) OperatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem) AppServiceConfigUtils.fromAppService(com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceConfigUtils.fromAppService) QueryFactory(com.microsoft.azure.maven.queryer.QueryFactory) PricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) ArrayList(java.util.ArrayList) Region(com.microsoft.azure.toolkit.lib.common.model.Region) Mojo(org.apache.maven.plugins.annotations.Mojo) DocumentException(org.dom4j.DocumentException) WebAppOption(com.microsoft.azure.maven.webapp.models.WebAppOption) Utils(com.microsoft.azure.toolkit.lib.common.utils.Utils) ObjectUtils(org.apache.commons.lang3.ObjectUtils) TextIoFactory(org.beryx.textio.TextIoFactory) Nonnull(javax.annotation.Nonnull) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) DeploymentSlotSetting(com.microsoft.azure.toolkit.lib.legacy.appservice.DeploymentSlotSetting) IOException(java.io.IOException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Deployment(com.microsoft.azure.maven.webapp.configuration.Deployment) Log(com.microsoft.azure.toolkit.lib.common.logging.Log) CustomTextIoStringListReader(com.microsoft.azure.maven.utils.CustomTextIoStringListReader) Collections(java.util.Collections) AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) WebAppOption(com.microsoft.azure.maven.webapp.models.WebAppOption) TextIO(org.beryx.textio.TextIO) AzureToolkitAuthenticationException(com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Example 12 with AzureToolkitAuthenticationException

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;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Azure(com.microsoft.azure.toolkit.lib.Azure) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) Arrays(java.util.Arrays) ApacheSenderFactory(com.microsoft.applicationinsights.internal.channel.common.ApacheSenderFactory) ProxyInfo(com.microsoft.azure.toolkit.lib.common.proxy.ProxyInfo) SneakyThrows(lombok.SneakyThrows) TextIO(org.beryx.textio.TextIO) Account(com.microsoft.azure.toolkit.lib.auth.Account) Parameter(org.apache.maven.plugins.annotations.Parameter) Settings(org.apache.maven.settings.Settings) StringUtils(org.apache.commons.lang3.StringUtils) AzureCloud(com.microsoft.azure.toolkit.lib.auth.AzureCloud) Proxy(org.apache.maven.settings.Proxy) MavenProject(org.apache.maven.project.MavenProject) Map(java.util.Map) MavenAuthConfiguration(com.microsoft.azure.maven.model.MavenAuthConfiguration) SystemPropertyUtils(com.microsoft.azure.maven.utils.SystemPropertyUtils) ProxyManager(com.microsoft.azure.toolkit.lib.common.proxy.ProxyManager) LoginFailureException(com.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException) SettingsDecrypter(org.apache.maven.settings.crypto.SettingsDecrypter) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) InstallationIdUtils(com.microsoft.azure.toolkit.lib.common.utils.InstallationIdUtils) AzureToolkitAuthenticationException(com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException) List(java.util.List) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) TextUtils(com.microsoft.azure.toolkit.lib.common.utils.TextUtils) DeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount) Optional(java.util.Optional) MavenAzureMessager(com.microsoft.azure.toolkit.maven.common.messager.MavenAzureMessager) AbstractMojo(org.apache.maven.plugin.AbstractMojo) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) AzureEnvironmentUtils(com.microsoft.azure.toolkit.lib.auth.util.AzureEnvironmentUtils) Getter(lombok.Getter) Component(org.apache.maven.plugins.annotations.Component) HashMap(java.util.HashMap) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AzureEnvironment(com.azure.core.management.AzureEnvironment) MavenAuthUtils(com.microsoft.azure.maven.utils.MavenAuthUtils) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) TextIoFactory(org.beryx.textio.TextIoFactory) DeviceCodeInfo(com.azure.identity.DeviceCodeInfo) ManagementFactory(java.lang.management.ManagementFactory) HttpLogDetailLevel(com.azure.core.http.policy.HttpLogDetailLevel) Nonnull(javax.annotation.Nonnull) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) AzureTelemetryClient(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetryClient) OutputStream(java.io.OutputStream) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) MavenSession(org.apache.maven.execution.MavenSession) Properties(java.util.Properties) SubscriptionOption(com.microsoft.azure.maven.model.SubscriptionOption) FileOutputStream(java.io.FileOutputStream) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) AzureTelemetry(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry) AzureTelemeter(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter) MavenResourcesFiltering(org.apache.maven.shared.filtering.MavenResourcesFiltering) Paths(java.nio.file.Paths) NumberUtils(org.apache.commons.lang3.math.NumberUtils) AzureLoginException(com.microsoft.azure.toolkit.lib.auth.exception.AzureLoginException) Log(com.microsoft.azure.toolkit.lib.common.logging.Log) CustomTextIoStringListReader(com.microsoft.azure.maven.utils.CustomTextIoStringListReader) AuthType(com.microsoft.azure.toolkit.lib.auth.model.AuthType) Collections(java.util.Collections) MavenDecryptException(com.microsoft.azure.maven.exception.MavenDecryptException) InputStream(java.io.InputStream) Account(com.microsoft.azure.toolkit.lib.auth.Account) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) DeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureToolkitAuthenticationException(com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException)

Example 13 with AzureToolkitAuthenticationException

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;
}
Also used : TelemetryConstants(com.microsoft.azure.gradle.temeletry.TelemetryConstants) Azure(com.microsoft.azure.toolkit.lib.Azure) AzureEnvironmentUtils(com.microsoft.azure.toolkit.lib.auth.util.AzureEnvironmentUtils) Account(com.microsoft.azure.toolkit.lib.auth.Account) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AzureEnvironment(com.azure.core.management.AzureEnvironment) AzureCloud(com.microsoft.azure.toolkit.lib.auth.AzureCloud) ObjectUtils(org.apache.commons.lang3.ObjectUtils) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) DeviceCodeInfo(com.azure.identity.DeviceCodeInfo) InvalidConfigurationException(com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException) Nonnull(javax.annotation.Nonnull) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) Mono(reactor.core.publisher.Mono) AuthConfiguration(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) AzureToolkitAuthenticationException(com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException) List(java.util.List) TelemetryAgent(com.microsoft.azure.gradle.temeletry.TelemetryAgent) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) DeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount) Optional(java.util.Optional) AuthType(com.microsoft.azure.toolkit.lib.auth.model.AuthType) Collections(java.util.Collections) Account(com.microsoft.azure.toolkit.lib.auth.Account) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) DeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureToolkitAuthenticationException(com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException)

Aggregations

AzureToolkitAuthenticationException (com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException)13 Nonnull (javax.annotation.Nonnull)6 DeviceCodeAccount (com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount)5 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)5 AzureEnvironment (com.azure.core.management.AzureEnvironment)4 Azure (com.microsoft.azure.toolkit.lib.Azure)4 Account (com.microsoft.azure.toolkit.lib.auth.Account)4 AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)4 AzureCloud (com.microsoft.azure.toolkit.lib.auth.AzureCloud)4 AuthType (com.microsoft.azure.toolkit.lib.auth.model.AuthType)3 AzureEnvironmentUtils (com.microsoft.azure.toolkit.lib.auth.util.AzureEnvironmentUtils)3 AzureMessager (com.microsoft.azure.toolkit.lib.common.messager.AzureMessager)3 IOException (java.io.IOException)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3 DeviceCodeInfo (com.azure.identity.DeviceCodeInfo)2 TokenCachePersistenceOptions (com.azure.identity.TokenCachePersistenceOptions)2