Search in sources :

Example 1 with LoginFailureException

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
            }
        }
    }
}
Also used : ConfigurationPrompter(com.microsoft.azure.maven.springcloud.config.ConfigurationPrompter) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) LoginFailureException(com.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) AppDeploymentRawConfig(com.microsoft.azure.maven.springcloud.config.AppDeploymentRawConfig) MavenDecryptException(com.microsoft.azure.maven.exception.MavenDecryptException) AppRawConfig(com.microsoft.azure.maven.springcloud.config.AppRawConfig) IOException(java.io.IOException) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator) InvalidConfigurationException(com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException)

Example 2 with LoginFailureException

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);
}
Also used : IAzureAccount(com.microsoft.azure.toolkit.lib.account.IAzureAccount) AzureCliAccount(com.microsoft.azure.toolkit.lib.auth.core.azurecli.AzureCliAccount) ServicePrincipalAccount(com.microsoft.azure.toolkit.lib.auth.core.serviceprincipal.ServicePrincipalAccount) OAuthAccount(com.microsoft.azure.toolkit.lib.auth.core.oauth.OAuthAccount) DeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount) LoginFailureException(com.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) AuthType(com.microsoft.azure.toolkit.lib.auth.model.AuthType) ServicePrincipalAccount(com.microsoft.azure.toolkit.lib.auth.core.serviceprincipal.ServicePrincipalAccount)

Aggregations

LoginFailureException (com.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException)2 MavenDecryptException (com.microsoft.azure.maven.exception.MavenDecryptException)1 AppDeploymentRawConfig (com.microsoft.azure.maven.springcloud.config.AppDeploymentRawConfig)1 AppRawConfig (com.microsoft.azure.maven.springcloud.config.AppRawConfig)1 ConfigurationPrompter (com.microsoft.azure.maven.springcloud.config.ConfigurationPrompter)1 IAzureAccount (com.microsoft.azure.toolkit.lib.account.IAzureAccount)1 AzureCliAccount (com.microsoft.azure.toolkit.lib.auth.core.azurecli.AzureCliAccount)1 DeviceCodeAccount (com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount)1 OAuthAccount (com.microsoft.azure.toolkit.lib.auth.core.oauth.OAuthAccount)1 ServicePrincipalAccount (com.microsoft.azure.toolkit.lib.auth.core.serviceprincipal.ServicePrincipalAccount)1 AuthType (com.microsoft.azure.toolkit.lib.auth.model.AuthType)1 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)1 InvalidConfigurationException (com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException)1 IOException (java.io.IOException)1 Supplier (java.util.function.Supplier)1 StringUtils (org.apache.commons.lang3.StringUtils)1 PluginParameterExpressionEvaluator (org.apache.maven.plugin.PluginParameterExpressionEvaluator)1 ExpressionEvaluator (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)1