Search in sources :

Example 66 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by microsoft.

the class SettingPanel method apply.

/**
 * Function triggered by any content change events.
 *
 * @param webAppOnLinuxDeployConfiguration configuration instance
 */
@Override
public void apply(WebAppOnLinuxDeployConfiguration webAppOnLinuxDeployConfiguration) {
    webAppOnLinuxDeployConfiguration.setDockerFilePath(containerSettingPanel.getDockerPath());
    // set ACR info
    webAppOnLinuxDeployConfiguration.setPrivateRegistryImageSetting(new PrivateRegistryImageSetting(containerSettingPanel.getServerUrl().replaceFirst("^https?://", "").replaceFirst("/$", ""), containerSettingPanel.getUserName(), containerSettingPanel.getPassword(), containerSettingPanel.getImageTag(), containerSettingPanel.getStartupFile()));
    final ISecureStore secureStore = AzureStoreManager.getInstance().getSecureStore();
    secureStore.savePassword(PRIVATE_DOCKER_REGISTRY, containerSettingPanel.getServerUrl(), containerSettingPanel.getUserName(), containerSettingPanel.getPassword());
    webAppOnLinuxDeployConfiguration.setTargetPath(getTargetPath());
    webAppOnLinuxDeployConfiguration.setTargetName(getTargetName());
    // set web app info
    if (rdoUseExist.isSelected()) {
        // existing web app
        webAppOnLinuxDeployConfiguration.setCreatingNewWebAppOnLinux(false);
        IWebApp selectedWebApp = null;
        final int index = webAppTable.getSelectedRow();
        if (cachedWebAppList != null && index >= 0 && index < cachedWebAppList.size()) {
            selectedWebApp = cachedWebAppList.get(webAppTable.getSelectedRow());
        }
        if (selectedWebApp != null) {
            webAppOnLinuxDeployConfiguration.setWebAppId(selectedWebApp.id());
            webAppOnLinuxDeployConfiguration.setAppName(selectedWebApp.name());
            webAppOnLinuxDeployConfiguration.setSubscriptionId(selectedWebApp.subscriptionId());
            webAppOnLinuxDeployConfiguration.setResourceGroupName(selectedWebApp.resourceGroup());
        } else {
            webAppOnLinuxDeployConfiguration.setWebAppId(null);
            webAppOnLinuxDeployConfiguration.setAppName(null);
            webAppOnLinuxDeployConfiguration.setSubscriptionId(null);
            webAppOnLinuxDeployConfiguration.setResourceGroupName(null);
        }
    } else if (rdoCreateNew.isSelected()) {
        // create new web app
        webAppOnLinuxDeployConfiguration.setCreatingNewWebAppOnLinux(true);
        webAppOnLinuxDeployConfiguration.setWebAppId("");
        webAppOnLinuxDeployConfiguration.setAppName(textAppName.getText());
        final Subscription selectedSubscription = (Subscription) comboSubscription.getSelectedItem();
        if (selectedSubscription != null) {
            webAppOnLinuxDeployConfiguration.setSubscriptionId(selectedSubscription.getId());
        }
        // resource group
        if (rdoUseExistResGrp.isSelected()) {
            // existing RG
            webAppOnLinuxDeployConfiguration.setCreatingNewResourceGroup(false);
            final ResourceGroup selectedRg = (ResourceGroup) comboResourceGroup.getSelectedItem();
            if (selectedRg != null) {
                webAppOnLinuxDeployConfiguration.setResourceGroupName(selectedRg.getName());
            } else {
                webAppOnLinuxDeployConfiguration.setResourceGroupName(null);
            }
        } else if (rdoCreateResGrp.isSelected()) {
            // new RG
            webAppOnLinuxDeployConfiguration.setCreatingNewResourceGroup(true);
            webAppOnLinuxDeployConfiguration.setResourceGroupName(txtNewResGrp.getText());
        }
        // app service plan
        if (rdoCreateAppServicePlan.isSelected()) {
            webAppOnLinuxDeployConfiguration.setCreatingNewAppServicePlan(true);
            webAppOnLinuxDeployConfiguration.setAppServicePlanName(txtCreateAppServicePlan.getText());
            final Region selectedLocation = (Region) cbLocation.getSelectedItem();
            if (selectedLocation != null) {
                webAppOnLinuxDeployConfiguration.setLocationName(selectedLocation.getName());
            } else {
                webAppOnLinuxDeployConfiguration.setLocationName(null);
            }
            final PricingTier selectedPricingTier = (PricingTier) cbPricing.getSelectedItem();
            if (selectedPricingTier != null) {
                webAppOnLinuxDeployConfiguration.setPricingSkuTier(selectedPricingTier.getTier());
                webAppOnLinuxDeployConfiguration.setPricingSkuSize(selectedPricingTier.getSize());
            } else {
                webAppOnLinuxDeployConfiguration.setPricingSkuTier(null);
                webAppOnLinuxDeployConfiguration.setPricingSkuSize(null);
            }
        } else if (rdoUseExistAppServicePlan.isSelected()) {
            webAppOnLinuxDeployConfiguration.setCreatingNewAppServicePlan(false);
            final AppServicePlan selectedAsp = (AppServicePlan) cbExistAppServicePlan.getSelectedItem();
            if (selectedAsp != null) {
                webAppOnLinuxDeployConfiguration.setAppServicePlanId(selectedAsp.id());
            } else {
                webAppOnLinuxDeployConfiguration.setAppServicePlanId(null);
            }
        }
    }
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) PricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier) ISecureStore(com.microsoft.azure.toolkit.ide.common.store.ISecureStore) Region(com.microsoft.azure.toolkit.lib.common.model.Region) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) AppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.impl.AppServicePlan)

Example 67 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-gradle-plugins by microsoft.

the class GradleAuthHelper method login.

public static String login(GradleAuthConfig auth, String subscriptionId) {
    try {
        Account account = login(toAuthConfiguration(ObjectUtils.firstNonNull(auth, new GradleAuthConfig())));
        final List<Subscription> subscriptions = account.getSubscriptions();
        final String targetSubscriptionId = getTargetSubscriptionId(subscriptionId, subscriptions, account.getSelectedSubscriptions());
        checkSubscription(subscriptions, targetSubscriptionId);
        Azure.az(AzureAccount.class).account().selectSubscription(Collections.singletonList(targetSubscriptionId));
        printCurrentSubscription(account);
        return targetSubscriptionId;
    } catch (InvalidConfigurationException e) {
        throw new AzureToolkitAuthenticationException("Failed to authenticate with Azure due to error: " + e.getMessage());
    }
}
Also used : 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) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) AzureToolkitAuthenticationException(com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException) InvalidConfigurationException(com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException)

Example 68 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-gradle-plugins by microsoft.

the class GradleAuthHelper method getTargetSubscriptionId.

private static String getTargetSubscriptionId(String defaultSubscriptionId, List<Subscription> subscriptions, List<Subscription> selectedSubscriptions) {
    String targetSubscriptionId = defaultSubscriptionId;
    if (StringUtils.isBlank(targetSubscriptionId) && !selectedSubscriptions.isEmpty()) {
        targetSubscriptionId = selectedSubscriptions.stream().filter(Subscription::isSelected).map(Subscription::getId).findFirst().orElse(null);
    }
    if (StringUtils.isBlank(targetSubscriptionId) && !subscriptions.isEmpty()) {
        targetSubscriptionId = subscriptions.stream().map(Subscription::getId).findFirst().orElse(null);
    }
    TelemetryAgent.getInstance().addDefaultProperty(TelemetryConstants.SUBSCRIPTION_ID_KEY, targetSubscriptionId);
    return targetSubscriptionId;
}
Also used : AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 69 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class CreateRedisCacheForm method initWidgetListeners.

private void initWidgetListeners() {
    txtRedisName.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }

        @Override
        public void removeUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }

        @Override
        public void changedUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }
    });
    cbSubs.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            currentSub = (Subscription) cbSubs.getSelectedItem();
            cbLocations.setSubscription(currentSub);
            fillResourceGrps(currentSub);
            validateEmptyFields();
        }
    });
    rdoCreateNewGrp.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            txtNewResGrp.setVisible(true);
            cbUseExist.setVisible(false);
            newResGrp = true;
            validateEmptyFields();
        }
    });
    txtNewResGrp.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }

        @Override
        public void removeUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }

        @Override
        public void changedUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }
    });
    rdoUseExist.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            txtNewResGrp.setVisible(false);
            cbUseExist.setVisible(true);
            newResGrp = false;
            validateEmptyFields();
        }
    });
    cbUseExist.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            validateEmptyFields();
        }
    });
    cbLocations.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            validateEmptyFields();
        }
    });
    lblPricing.addMouseListener(new LinkListener(PRICING_LINK));
    cbPricing.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            validateEmptyFields();
        }
    });
    chkNoSSL.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (chkNoSSL.isSelected()) {
                noSSLPort = true;
            } else {
                noSSLPort = false;
            }
        }
    });
}
Also used : DocumentListener(javax.swing.event.DocumentListener) MouseEvent(java.awt.event.MouseEvent) ActionListener(java.awt.event.ActionListener) LinkListener(com.microsoft.intellij.helpers.LinkListener) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) DocumentEvent(javax.swing.event.DocumentEvent) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 70 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class RedisCreationDialog method onSubscriptionChanged.

private void onSubscriptionChanged(final ItemEvent e) {
    if (e.getStateChange() == ItemEvent.SELECTED) {
        final Subscription subscription = (Subscription) e.getItem();
        this.resourceGroupComboBox.setSubscription(subscription);
        this.regionComboBox.setSubscription(subscription);
    } else if (e.getStateChange() == ItemEvent.DESELECTED) {
        this.resourceGroupComboBox.setSubscription(null);
        this.regionComboBox.setSubscription(null);
    }
}
Also used : Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Aggregations

Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)130 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)26 Region (com.microsoft.azure.toolkit.lib.common.model.Region)18 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)18 AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)15 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 Project (com.intellij.openapi.project.Project)8 Azure (com.microsoft.azure.toolkit.lib.Azure)8 IAppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan)8 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)8 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)8 HashMap (java.util.HashMap)8 List (java.util.List)8 StringUtils (org.apache.commons.lang3.StringUtils)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 Point (org.eclipse.swt.graphics.Point)8 GridData (org.eclipse.swt.layout.GridData)8 Combo (org.eclipse.swt.widgets.Combo)8