Search in sources :

Example 1 with ISecureStore

use of com.microsoft.azure.toolkit.ide.common.store.ISecureStore in project azure-tools-for-java by Microsoft.

the class SettingPanel method apply.

/**
 * Function triggered by any content change events.
 */
@Override
public void apply(PushImageRunConfiguration pushImageRunConfiguration) {
    pushImageRunConfiguration.setDockerFilePath(containerSettingPanel.getDockerPath());
    // set ACR info
    pushImageRunConfiguration.setPrivateRegistryImageSetting(new PrivateRegistryImageSetting(containerSettingPanel.getServerUrl().replaceFirst("^https?://", "").replaceFirst("/$", ""), containerSettingPanel.getUserName(), containerSettingPanel.getPassword(), containerSettingPanel.getImageTag(), ""));
    final ISecureStore secureStore = AzureStoreManager.getInstance().getSecureStore();
    secureStore.savePassword(PRIVATE_DOCKER_REGISTRY, containerSettingPanel.getServerUrl(), containerSettingPanel.getUserName(), containerSettingPanel.getPassword());
    // set target
    pushImageRunConfiguration.setTargetPath(getTargetPath());
    pushImageRunConfiguration.setTargetName(getTargetName());
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) ISecureStore(com.microsoft.azure.toolkit.ide.common.store.ISecureStore)

Example 2 with ISecureStore

use of com.microsoft.azure.toolkit.ide.common.store.ISecureStore in project azure-tools-for-java by Microsoft.

the class SettingPanel method resetFromConfig.

/**
 * Function triggered in constructing the panel.
 *
 * @param conf configuration instance
 */
@Override
public void resetFromConfig(PushImageRunConfiguration conf) {
    if (!isMavenProject()) {
        containerSettingPanel.setDockerPath(DockerUtil.getDefaultDockerFilePathIfExist(getProjectBasePath()));
    }
    PrivateRegistryImageSetting acrInfo = conf.getPrivateRegistryImageSetting();
    if (StringUtils.isEmpty(acrInfo.getPassword())) {
        final ISecureStore secureStore = AzureStoreManager.getInstance().getSecureStore();
        secureStore.migratePassword(containerSettingPanel.getServerUrl(), containerSettingPanel.getUserName(), PRIVATE_DOCKER_REGISTRY, containerSettingPanel.getServerUrl(), containerSettingPanel.getUserName());
        acrInfo.setPassword(secureStore.loadPassword(PRIVATE_DOCKER_REGISTRY, acrInfo.getServerUrl(), acrInfo.getUsername()));
    }
    containerSettingPanel.setTxtFields(acrInfo);
    // load dockerFile path from existing configuration.
    if (!Utils.isEmptyString(conf.getDockerFilePath())) {
        containerSettingPanel.setDockerPath(conf.getDockerFilePath());
    }
    containerSettingPanel.onListRegistries();
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) ISecureStore(com.microsoft.azure.toolkit.ide.common.store.ISecureStore)

Example 3 with ISecureStore

use of com.microsoft.azure.toolkit.ide.common.store.ISecureStore in project azure-tools-for-java by Microsoft.

the class SettingPanel method resetFromConfig.

/**
 * Function triggered in constructing the panel.
 *
 * @param conf configuration instance
 */
@Override
public void resetFromConfig(@NotNull WebAppOnLinuxDeployConfiguration conf) {
    if (!isMavenProject()) {
        containerSettingPanel.setDockerPath(DockerUtil.getDefaultDockerFilePathIfExist(getProjectBasePath()));
    }
    // load dockerFile path from existing configuration.
    if (!Utils.isEmptyString(conf.getDockerFilePath())) {
        containerSettingPanel.setDockerPath(conf.getDockerFilePath());
    }
    final PrivateRegistryImageSetting acrInfo = conf.getPrivateRegistryImageSetting();
    if (StringUtils.isNotEmpty(acrInfo.getServerUrl())) {
        final ISecureStore secureStore = AzureStoreManager.getInstance().getSecureStore();
        secureStore.migratePassword(acrInfo.getServerUrl(), acrInfo.getUsername(), PRIVATE_DOCKER_REGISTRY, acrInfo.getServerUrl(), acrInfo.getUsername());
        acrInfo.setPassword(secureStore.loadPassword(PRIVATE_DOCKER_REGISTRY, acrInfo.getServerUrl(), acrInfo.getUsername()));
    }
    containerSettingPanel.setTxtFields(acrInfo);
    // cache for table/combo selection
    defaultSubscriptionId = conf.getSubscriptionId();
    defaultWebAppId = conf.getWebAppId();
    defaultLocationName = conf.getLocationName();
    defaultPricingTier = StringUtils.isEmpty(conf.getPricingSkuTier()) ? Constant.WEBAPP_CONTAINER_DEFAULT_PRICING_TIER : new PricingTier(conf.getPricingSkuTier(), conf.getPricingSkuSize()).toString();
    defaultResourceGroup = conf.getResourceGroupName();
    defaultAppServicePlanId = conf.getAppServicePlanId();
    // pnlUseExisting
    loadWebAppList();
    // pnlCreateNew
    // including related RG & Region
    webAppOnLinuxDeployPresenter.onLoadSubscriptionList();
    webAppOnLinuxDeployPresenter.onLoadPricingTierList();
    final boolean creatingRg = conf.isCreatingNewResourceGroup();
    rdoCreateResGrp.setSelected(creatingRg);
    rdoUseExistResGrp.setSelected(!creatingRg);
    updateResourceGroupEnabled();
    if (creatingRg) {
        txtNewResGrp.setText(conf.getResourceGroupName());
    }
    final boolean creatingAsp = conf.isCreatingNewAppServicePlan();
    rdoCreateAppServicePlan.setSelected(creatingAsp);
    rdoUseExistAppServicePlan.setSelected(!creatingAsp);
    updateAppServicePlanEnabled();
    if (creatingAsp) {
        txtCreateAppServicePlan.setText(conf.getAppServicePlanName());
    }
    // active panel
    final boolean creatingApp = conf.isCreatingNewWebAppOnLinux();
    if (creatingApp) {
        textAppName.setText(conf.getAppName());
    }
    rdoCreateNew.setSelected(creatingApp);
    rdoUseExist.setSelected(!creatingApp);
    updatePanelVisibility();
    // default value for new resources
    final DateFormat df = new SimpleDateFormat("yyMMddHHmmss");
    final String date = df.format(new Date());
    if (Utils.isEmptyString(textAppName.getText())) {
        textAppName.setText(String.format("%s-%s", APP_NAME_PREFIX, date));
    }
    if (Utils.isEmptyString(txtNewResGrp.getText())) {
        txtNewResGrp.setText(String.format("%s-%s", RESOURCE_GROUP_NAME_PREFIX, date));
    }
    if (Utils.isEmptyString(txtCreateAppServicePlan.getText())) {
        txtCreateAppServicePlan.setText(String.format("%s-%s", APP_SERVICE_PLAN_NAME_PREFIX, date));
    }
}
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) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with ISecureStore

use of com.microsoft.azure.toolkit.ide.common.store.ISecureStore 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)

Aggregations

ISecureStore (com.microsoft.azure.toolkit.ide.common.store.ISecureStore)4 PrivateRegistryImageSetting (com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)4 PricingTier (com.microsoft.azure.toolkit.lib.appservice.model.PricingTier)2 IAppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan)1 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)1 AppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.impl.AppServicePlan)1 Region (com.microsoft.azure.toolkit.lib.common.model.Region)1 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)1 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1