Search in sources :

Example 1 with AzureEnvironment

use of com.azure.core.management.AzureEnvironment in project azure-tools-for-java by Microsoft.

the class AzurePanel method init.

@Override
public void init() {
    if (AzurePlugin.IS_ANDROID_STUDIO) {
        return;
    }
    Messages.configureMessagePaneUi(allowTelemetryComment, message("settings.root.telemetry.notice"));
    allowTelemetryComment.setForeground(UIUtil.getContextHelpForeground());
    final ComboBoxModel<AzureEnvironment> model = new DefaultComboBoxModel<>(Azure.az(AzureCloud.class).list().toArray(new AzureEnvironment[0]));
    azureEnvironmentComboBox.setModel(model);
    azureEnvironmentComboBox.setRenderer(new SimpleListCellRenderer<>() {

        @Override
        public void customize(@NotNull JList list, AzureEnvironment value, int index, boolean selected, boolean hasFocus) {
            setText(azureEnvironmentDisplayString(value));
        }
    });
    azureEnvDesc.setForeground(UIUtil.getContextHelpForeground());
    azureEnvDesc.setMaximumSize(new Dimension());
    azureEnvironmentComboBox.addItemListener(e -> {
        if (e.getStateChange() == ItemEvent.SELECTED) {
            displayDescriptionForAzureEnv();
        }
    });
    displayDescriptionForAzureEnv();
    setData(Azure.az().config());
}
Also used : AzureEnvironment(com.azure.core.management.AzureEnvironment) AzureCloud(com.microsoft.azure.toolkit.lib.auth.AzureCloud) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Dimension(java.awt.Dimension) JList(javax.swing.JList)

Example 2 with AzureEnvironment

use of com.azure.core.management.AzureEnvironment in project azure-tools-for-java by Microsoft.

the class AzurePanel method getData.

public AzureConfiguration getData() {
    final AzureConfiguration data = new AzureConfiguration();
    data.setCloud(AzureEnvironmentUtils.azureEnvironmentToString((AzureEnvironment) azureEnvironmentComboBox.getSelectedItem()));
    if (savePasswordComboBox.getValue() != null) {
        data.setDatabasePasswordSaveType(savePasswordComboBox.getValue().name());
    }
    data.setTelemetryEnabled(allowTelemetryCheckBox.isSelected());
    data.setFunctionCoreToolsPath(funcCoreToolsPath.getItem());
    return data;
}
Also used : AzureEnvironment(com.azure.core.management.AzureEnvironment) AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration)

Example 3 with AzureEnvironment

use of com.azure.core.management.AzureEnvironment in project azure-tools-for-java by Microsoft.

the class AzurePanel method doOKAction.

@Override
public boolean doOKAction() {
    final AzureConfiguration data = getData();
    // set partial config to global config
    final AzureConfiguration config = Azure.az().config();
    config.setCloud(data.getCloud());
    config.setTelemetryEnabled(data.getTelemetryEnabled());
    config.setDatabasePasswordSaveType(data.getDatabasePasswordSaveType());
    config.setFunctionCoreToolsPath(data.getFunctionCoreToolsPath());
    final String userAgent = String.format(AzurePlugin.USER_AGENT, AzurePlugin.PLUGIN_VERSION, config.getTelemetryEnabled() ? config.getMachineId() : StringUtils.EMPTY);
    config.setUserAgent(userAgent);
    CommonSettings.setUserAgent(config.getUserAgent());
    // we need to get rid of AuthMethodManager, using az.azure_account
    if (AuthMethodManager.getInstance().isSignedIn()) {
        final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
        final String azureEnv = authMethodManager.getAuthMethodDetails().getAzureEnv();
        final AzureEnvironment currentEnv = AzureEnvironmentUtils.stringToAzureEnvironment(azureEnv);
        if (!Objects.equals(currentEnv, azureEnvironmentComboBox.getSelectedItem())) {
            EventUtil.executeWithLog(ACCOUNT, SIGNOUT, (operation) -> {
                authMethodManager.signOut();
            });
        }
    }
    if (StringUtils.isNotBlank(config.getCloud())) {
        Azure.az(AzureCloud.class).setByName(config.getCloud());
    }
    AzureConfigInitializer.saveAzConfig();
    return true;
}
Also used : AzureEnvironment(com.azure.core.management.AzureEnvironment) AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration) AzureCloud(com.microsoft.azure.toolkit.lib.auth.AzureCloud) AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager)

Example 4 with AzureEnvironment

use of com.azure.core.management.AzureEnvironment in project azure-tools-for-java by Microsoft.

the class AzurePanel method displayDescriptionForAzureEnv.

private void displayDescriptionForAzureEnv() {
    if (AuthMethodManager.getInstance().isSignedIn()) {
        final String azureEnv = AuthMethodManager.getInstance().getAuthMethodDetails().getAzureEnv();
        final AzureEnvironment currentEnv = AzureEnvironmentUtils.stringToAzureEnvironment(azureEnv);
        final String currentEnvStr = azureEnvironmentToString(currentEnv);
        if (Objects.equals(currentEnv, azureEnvironmentComboBox.getSelectedItem())) {
            setTextToLabel(azureEnvDesc, "You are currently signed in with environment: " + currentEnvStr);
            azureEnvDesc.setIcon(AllIcons.General.Information);
        } else {
            setTextToLabel(azureEnvDesc, String.format("You are currently signed in with environment: %s, your change will sign out your account.", currentEnvStr));
            azureEnvDesc.setIcon(AllIcons.General.Warning);
        }
    } else {
        setTextToLabel(azureEnvDesc, "You are currently not signed, the environment will be applied when you sign in next time.");
        azureEnvDesc.setIcon(AllIcons.General.Warning);
    }
}
Also used : AzureEnvironment(com.azure.core.management.AzureEnvironment)

Example 5 with AzureEnvironment

use of com.azure.core.management.AzureEnvironment in project azure-tools-for-java by Microsoft.

the class FunctionAppService method createApplicationInsights.

@Nullable
private ApplicationInsightsEntity createApplicationInsights(final FunctionAppConfig config) {
    try {
        AzureMessager.getMessager().info(APPLICATION_INSIGHTS_CREATE_START);
        final AzureEnvironment environment = Azure.az(AzureAccount.class).account().getEnvironment();
        final ApplicationInsightsEntity resource = Azure.az(ApplicationInsights.class).create(config.getSubscription().getId(), config.getResourceGroup().getName(), config.getRegion(), config.getMonitorConfig().getApplicationInsightsConfig().getName());
        AzureMessager.getMessager().info(String.format(APPLICATION_INSIGHTS_CREATED, resource.getName(), IdentityAzureManager.getInstance().getPortalUrl(), resource.getId()));
        return resource;
    } catch (final Exception e) {
        AzureMessager.getMessager().warning(String.format(APPLICATION_INSIGHTS_CREATE_FAILED, e.getMessage()));
        return null;
    }
}
Also used : AzureEnvironment(com.azure.core.management.AzureEnvironment) ApplicationInsights(com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsights) ApplicationInsightsEntity(com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsightsEntity) IOException(java.io.IOException) ManagementException(com.azure.core.management.exception.ManagementException) Nullable(javax.annotation.Nullable)

Aggregations

AzureEnvironment (com.azure.core.management.AzureEnvironment)5 AzureConfiguration (com.microsoft.azure.toolkit.lib.AzureConfiguration)2 AzureCloud (com.microsoft.azure.toolkit.lib.auth.AzureCloud)2 ManagementException (com.azure.core.management.exception.ManagementException)1 ApplicationInsights (com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsights)1 ApplicationInsightsEntity (com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsightsEntity)1 AuthMethodManager (com.microsoft.azuretools.authmanage.AuthMethodManager)1 Dimension (java.awt.Dimension)1 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 JList (javax.swing.JList)1