Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
data: undefined
}];
let plans: AppServicePlan[] = await AppServicePlanListStep.getPlans(wizardContext);
const famFilter: RegExp | undefined = wizardContext.planSkuFamilyFilter;
if (famFilter) {
plans = plans.filter(plan => !plan.sku || !plan.sku.family || famFilter.test(plan.sku.family));
}
for (const plan of plans) {
const isNewSiteLinux: boolean = wizardContext.newSiteOS === WebsiteOS.linux;
let isPlanLinux: boolean = nonNullProp(plan, 'kind').toLowerCase().includes(WebsiteOS.linux);
if (plan.sku && plan.sku.family === 'EP') {
// elastic premium plans do not have the os in the kind, so we have to check the "reserved" property
const client: WebSiteManagementClient = createAzureClient(wizardContext, WebSiteManagementClient);
const epPlan: AppServicePlan = await client.appServicePlans.get(nonNullProp(plan, 'resourceGroup'), nonNullProp(plan, 'name'));
isPlanLinux = !!epPlan.reserved;
}
// plan.kind will contain "linux" for Linux plans, but will _not_ contain "windows" for Windows plans. Thus we check "isLinux" for both cases
if (isNewSiteLinux === isPlanLinux) {
picks.push({
id: plan.id,
label: nonNullProp(plan, 'name'),
description: `${nonNullProp(plan, 'sku').name} (${plan.geoRegion})`,
detail: plan.resourceGroup,
data: plan
});
}
}
const newSiteConfig: SiteConfig = {};
let storageConnectionString: string | undefined;
let fileShareName: string | undefined;
if (wizardContext.newSiteKind === AppKind.app) {
newSiteConfig.linuxFxVersion = wizardContext.newSiteRuntime;
} else {
if (wizardContext.newSiteOS === 'linux') {
if (wizardContext.useConsumptionPlan) {
newSiteConfig.use32BitWorkerProcess = false; // Needs to be explicitly set to false per the platform team
} else {
newSiteConfig.linuxFxVersion = getFunctionAppLinuxFxVersion(nonNullProp(wizardContext, 'newSiteRuntime'));
}
}
const storageClient: StorageManagementClient = createAzureClient(wizardContext, StorageManagementClient);
const storageAccount: StorageAccount = nonNullProp(wizardContext, 'storageAccount');
const [, storageResourceGroup] = nonNullValue(nonNullProp(storageAccount, 'id').match(/\/resourceGroups\/([^/]+)\//), 'Invalid storage account id');
const keysResult: StorageAccountListKeysResult = await storageClient.storageAccounts.listKeys(storageResourceGroup, nonNullProp(storageAccount, 'name'));
fileShareName = getNewFileShareName(nonNullProp(wizardContext, 'newSiteName'));
// https://github.com/Azure/azure-sdk-for-node/issues/4706
const endpointSuffix: string = wizardContext.environment.storageEndpointSuffix.replace(/^\./, '');
storageConnectionString = '';
if (keysResult.keys && keysResult.keys[0].value) {
storageConnectionString = `DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};AccountKey=${keysResult.keys[0].value};EndpointSuffix=${endpointSuffix}`;
}
}
public async execute(wizardContext: IAppServiceWizardContext, progress: Progress<{ message?: string; increment?: number }>): Promise {
const creatingNewApp: string = wizardContext.newSiteKind === AppKind.functionapp ?
localize('creatingNewFunctionApp', 'Creating new function app "{0}"...', wizardContext.newSiteName) :
localize('creatingNewWebApp', 'Creating new web app "{0}"...', wizardContext.newSiteName);
ext.outputChannel.appendLog(creatingNewApp);
progress.report({ message: creatingNewApp });
const client: WebSiteManagementClient = createAzureClient(wizardContext, WebSiteManagementClient);
wizardContext.site = await client.webApps.createOrUpdate(nonNullValueAndProp(wizardContext.resourceGroup, 'name'), nonNullProp(wizardContext, 'newSiteName'), {
name: wizardContext.newSiteName,
kind: wizardContext.newSiteKind,
location: nonNullValueAndProp(wizardContext.location, 'name'),
serverFarmId: wizardContext.plan ? wizardContext.plan.id : undefined,
clientAffinityEnabled: wizardContext.newSiteKind === AppKind.app,
siteConfig: await this.getNewSiteConfig(wizardContext),
reserved: wizardContext.newSiteOS === WebsiteOS.linux // The secret property - must be set to true to make it a Linux plan. Confirmed by the team who owns this API.
});
}
export async function createSlot(root: ISiteTreeRoot, existingSlots: AzureTreeItem[], context: ICreateChildImplContext): Promise {
const client: WebSiteManagementClient = createAzureClient(root, WebSiteManagementClient);
const slotName: string = (await ext.ui.showInputBox({
prompt: localize('enterSlotName', 'Enter a unique name for the new deployment slot'),
validateInput: async (value: string | undefined): Promise => validateSlotName(value, client, root)
})).trim();
const newDeploymentSlot: Site = {
name: slotName,
kind: root.client.kind,
location: root.client.location,
serverFarmId: root.client.serverFarmId,
siteConfig: {
appSettings: [] // neccesary to have clean appSettings; by default it copies the production's slot
}
};
const configurationSource: SiteClient | undefined = await chooseConfigurationSource(root, existingSlots);
export async function deleteCosmosDBAccount(node: AzureTreeItem): Promise {
const message: string = `Are you sure you want to delete account '${node.label}' and its contents?`;
const result = await ext.ui.showWarningMessage(message, { modal: true }, DialogResponses.deleteResponse, DialogResponses.cancel);
if (result === DialogResponses.deleteResponse) {
const client: CosmosDBManagementClient = createAzureClient(node.root, CosmosDBManagementClient);
const resourceGroup: string = azureUtils.getResourceGroupFromId(node.fullId);
const accountName: string = azureUtils.getAccountNameFromId(node.fullId);
const deletingMessage: string = `Deleting account "${accountName}"...`;
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: deletingMessage }, async () => {
await client.databaseAccounts.deleteMethod(resourceGroup, accountName);
});
// don't wait
vscode.window.showInformationMessage(`Successfully deleted account "${accountName}".`);
} else {
throw new UserCancelledError();
}
}
private get _client(): WebSiteManagementClient {
return createAzureClient(this._subscription, WebSiteManagementClient);
}
public async loadMoreChildrenImpl(clearCache: boolean, _context: IActionContext): Promise {
_context.telemetry.properties.nodeType = "IotDps";
if (clearCache) {
this._nextLink = undefined;
}
const client: IotDpsClient = createAzureClient(this.root, IotDpsClient);
const dpsCollection: IotDpsModels.ProvisioningServiceDescriptionListResult = this._nextLink === undefined ?
await client.iotDpsResource.listBySubscription() :
await client.iotDpsResource.listBySubscriptionNext(this._nextLink);
this._nextLink = dpsCollection.nextLink;
return dpsCollection.map((dps: IotDpsModels.ProvisioningServiceDescription) => new DpsResourceTreeItem(this, dps));
}
}
public async loadMoreChildrenImpl(_clearCache: boolean): Promise {
const client: CosmosDBManagementClient = createAzureClient(this.root, CosmosDBManagementClient);
const accounts: DatabaseAccountsListResult = await client.databaseAccounts.list();
return await this.createTreeItemsWithErrorHandling(
accounts,
'invalidCosmosDBAccount',
async (db: DatabaseAccount) => await this.initChild(client, db),
(db: DatabaseAccount) => db.name
);
}
public async loadMoreChildrenImpl(clearCache: boolean, _context: IActionContext): Promise {
_context.telemetry.properties.nodeType = "IotHub";
if (clearCache) {
this._nextLink = undefined;
}
const client: IotHubClient = createAzureClient(this.root, IotHubClient);
const iotHubCollection: IotHubModels.IotHubDescriptionListResult = this._nextLink === undefined ?
await client.iotHubResource.listBySubscription() :
await client.iotHubResource.listBySubscriptionNext(this._nextLink);
this._nextLink = iotHubCollection.nextLink;
return iotHubCollection.map((iotHub: IotHubModels.IotHubDescription) => new IoTHubResourceTreeItem(this, iotHub));
}
}
public static async getPlans(wizardContext: IAppServiceWizardContext): Promise {
if (wizardContext.plansTask === undefined) {
const client: WebSiteManagementClient = createAzureClient(wizardContext, WebSiteManagementClient);
wizardContext.plansTask = uiUtils.listAll(client.appServicePlans, client.appServicePlans.list());
}
return await wizardContext.plansTask;
}