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);
}
}
}
}
use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.
the class ContainerRegistryMvpModelTest method testListContainerRegistries.
@Test
public void testListContainerRegistries() throws IOException {
List<Subscription> subscriptions = new ArrayList<Subscription>();
Subscription sub1 = mock(Subscription.class);
when(sub1.getId()).thenReturn("1");
Subscription sub2 = mock(Subscription.class);
when(sub2.getId()).thenReturn("2");
Subscription sub3 = mock(Subscription.class);
when(sub3.getId()).thenReturn("3");
when(mvpModel.getSelectedSubscriptions()).thenReturn(subscriptions);
ContainerRegistryMvpModel mockModel = spy(containerRegistryMvpModel);
when(authMethodManagerMock.getAzureClient(anyString())).thenReturn(azureMock);
when(registriesMock.list()).thenReturn(new PagedList<Registry>() {
@Override
public Page<Registry> nextPage(String nextPageLink) throws RestException, IOException {
return null;
}
});
mockModel.listContainerRegistries(false);
verify(mockModel, times(0)).listRegistryBySubscriptionId(anyString(), eq(false));
subscriptions.add(sub1);
subscriptions.add(sub2);
subscriptions.add(sub3);
mockModel.listContainerRegistries(false);
verify(mockModel, times(3)).listRegistryBySubscriptionId(anyString(), eq(false));
reset(mockModel);
mockModel.listContainerRegistries(true);
verify(mockModel, times(3)).listRegistryBySubscriptionId(anyString(), eq(true));
}
use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.
the class ContainerRegistryMvpModel method listContainerRegistries.
/**
* Get Registry instances mapped by Subscription id.
*/
public List<ResourceEx<Registry>> listContainerRegistries(boolean force) {
List<ResourceEx<Registry>> registryList = new ArrayList<>();
List<Subscription> subscriptions = az(AzureAccount.class).account().getSelectedSubscriptions();
for (Subscription sub : subscriptions) {
registryList.addAll(listRegistryBySubscriptionId(sub.getId(), force));
}
return registryList;
}
use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.
the class AzureManagerBase method getSubscriptionsWithTenant.
@Override
@AzureOperation(name = "account|subscription.list.tenant|authorized", type = AzureOperation.Type.SERVICE)
public List<Pair<Subscription, Tenant>> getSubscriptionsWithTenant() {
final List<Pair<Subscription, Tenant>> subscriptions = new LinkedList<>();
final Azure.Authenticated authentication = authTenant(getCurrentTenantId());
// could be multi tenant - return all subscriptions for the current account
final List<Tenant> tenants = getTenants(authentication);
final List<String> failedTenantIds = new ArrayList<>();
for (final Tenant tenant : tenants) {
try {
final Azure.Authenticated tenantAuthentication = authTenant(tenant.tenantId());
final List<Subscription> tenantSubscriptions = getSubscriptions(tenantAuthentication);
for (final Subscription subscription : tenantSubscriptions) {
subscriptions.add(new Pair<>(subscription, tenant));
}
} catch (final Exception e) {
// just skip for cases user failing to get subscriptions of tenants he/she has no permission to get access token.
LOGGER.log(Level.WARNING, e.getMessage(), e);
failedTenantIds.add(tenant.tenantId());
}
}
if (!failedTenantIds.isEmpty()) {
final INotification nw = CommonSettings.getUiFactory().getNotificationWindow();
nw.deliver("Lack permission for some tenants", "You don't have permission on the tenant(s): " + StringUtils.join(failedTenantIds, ","));
}
return subscriptions;
}
use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by microsoft.
the class WebAppDeployDialog method fillAppServiceDetails.
private void fillAppServiceDetails() {
validated();
int selectedRow = table.getSelectionIndex();
if (selectedRow < 0) {
browserAppServiceDetails.setText("");
btnDelete.setEnabled(false);
return;
}
btnDelete.setEnabled(true);
String appServiceName = table.getItems()[selectedRow].getText(0);
IWebApp webApp = webAppDetailsMap.get(appServiceName);
IAppServicePlan asp = webApp.plan();
Subscription subscription = Azure.az(AzureAccount.class).account().getSubscription(webApp.subscriptionId());
StringBuilder sb = new StringBuilder();
sb.append(String.format("App Service name: %s \n", appServiceName));
sb.append(String.format("Subscription name: %s ; id: %s \n", subscription.getName(), subscription.getId()));
String aspName = asp == null ? "N/A" : asp.name();
String aspPricingTier = asp == null ? "N/A" : asp.entity().getPricingTier().toString();
sb.append(String.format("App Service Plan name: %s ; Pricing tier: %s \n", aspName, aspPricingTier));
String link = buildSiteLink(webApp, null);
sb.append(String.format("Link: <a href=\"%s\">%s</a> \n", link, link));
sb.append(String.format("<a href=\"%s\">%s</a> \n", ftpLinkString, "Show FTP deployment credentials"));
browserAppServiceDetails.setText(sb.toString());
}
Aggregations