import * as path from 'path' ; import { AzureWizardExecuteStep , AzureWizardPromptStep , IAzureQuickPickItem , ISubscriptionActionContext , IWizardOptions , StorageAccountKind , StorageAccountListStep , StorageAccountPerformance , StorageAccountReplication } from 'vscode-azureextensionui' ; import { localSettingsFileName } from '../../../constants' ; import { ext } from '../../../extensionVariables' ; import { BindingSettingValue } from '../../../funcConfig/function' ; import { getLocalSettingsJson , ILocalSettingsJson } from '../../../funcConfig/local.settings' ; import { localize } from '../../../localize' ; import { ResourceType } from '../../../templates/IBindingTemplate' ; import { getBindingSetting } from '../../createFunction/IFunctionWizardContext' ; import { IBindingWizardContext } from '../IBindingWizardContext' ; import { BindingSettingStepBase } from './BindingSettingStepBase' ; import { CosmosDBConnectionCreateStep } from './cosmosDB/CosmosDBConnectionCreateStep' ; import { CosmosDBListStep } from './cosmosDB/CosmosDBListStep' ; import { EventHubAuthRuleListStep } from './eventHub/EventHubAuthRuleListStep' ; import { EventHubConnectionCreateStep } from './eventHub/EventHubConnectionCreateStep' ; import { EventHubListStep } from './eventHub/EventHubListStep' ; import { EventHubNamespaceListStep } from './eventHub/EventHubNamespaceListStep' ; import { LocalAppSettingCreateStep } from './LocalAppSettingCreateStep' ; import { LocalAppSettingNameStep } from './LocalAppSettingNameStep' ; import { LocalAppSettingValueStep } from './LocalAppSettingValueStep' ; import { ServiceBusConnectionCreateStep } from './serviceBus/ServiceBusConnectionCreateStep' ; import { ServiceBusListStep } from './serviceBus/ServiceBusListStep' ; import { StorageConnectionCreateStep } from './StorageConnectionCreateStep' ; export class LocalAppSettingListStep extends BindingSettingStepBase { public async promptCore ( context ) { const localSettingsPath = path . join ( context . projectPath , localSettingsFileName ) ; const settings = await getLocalSettingsJson ( context , localSettingsPath ) ; const existingSettings = settings . Values ? Object . keys ( settings . Values ) : [ ] ; let picks = [ { label : localize ( 'newAppSetting' , '$(plus) Create new local app setting' ) , data : undefined } ] ; picks = picks . concat ( existingSettings . map ( ( s ) => { return { data : s , label : s } ; } ) ) ; const placeHolder = localize ( 'selectAppSetting' , 'Select setting from "{0}"' , localSettingsFileName ) ; return ( await context . ui . showQuickPick ( picks , { placeHolder } ) ) . data ; } public async getSubWizard ( context ) { if ( ! getBindingSetting ( context , this . _setting ) ) { const azurePromptSteps = [ ] ; const azureExecuteSteps = [ ] ; switch ( this . _setting . resourceType ) { case ResourceType . DocumentDB : azurePromptSteps . push ( new CosmosDBListStep ( ) ) ; azureExecuteSteps . push ( new CosmosDBConnectionCreateStep ( this . _setting ) ) ; break ; case ResourceType . Storage : azurePromptSteps . push ( new StorageAccountListStep ( { kind : StorageAccountKind . Storage , performance : StorageAccountPerformance . Standard , replication : StorageAccountReplication . LRS } , { kind : [ StorageAccountKind . BlobStorage ] , learnMoreLink : 'https://aka.ms/T5o0nf' } ) ) ; azureExecuteSteps . push ( new StorageConnectionCreateStep ( this . _setting ) ) ; break ; case ResourceType . ServiceBus : azurePromptSteps . push ( new ServiceBusListStep ( ) ) ; azureExecuteSteps . push ( new ServiceBusConnectionCreateStep ( this . _setting ) ) ; break ; case ResourceType . EventHub : azurePromptSteps . push ( new EventHubNamespaceListStep ( ) , new EventHubListStep ( ) , new EventHubAuthRuleListStep ( ) ) ; azureExecuteSteps . push ( new EventHubConnectionCreateStep ( this . _setting ) ) ; break ; default : const valueKey = this . _setting . name . toLowerCase ( ) + '_value' ; return { promptSteps : [ new LocalAppSettingNameStep ( this . _setting ) , new LocalAppSettingValueStep ( valueKey ) ] , executeSteps : [ new LocalAppSettingCreateStep ( this . _setting , valueKey ) ] } ; } const subscriptionPromptStep = await ext . azureAccountTreeItem . getSubscriptionPromptStep ( context ) ; if ( subscriptionPromptStep ) { azurePromptSteps . unshift ( subscriptionPromptStep ) ; } return { promptSteps : azurePromptSteps , executeSteps : azureExecuteSteps } ; } else { return undefined ; } } }