import { EventHubManagementClient , EventHubManagementModels } from '@azure/arm-eventhub' ; import { AzureWizardPromptStep } from 'vscode-azureextensionui' ; import { localize } from '../../../../localize' ; import { IBaseResourceWithName , promptForResource } from '../../../../utils/azure' ; import { createEventHubClient } from '../../../../utils/azureClients' ; import { nonNullProp } from '../../../../utils/nonNull' ; import { IEventHubWizardContext } from './IEventHubWizardContext' ; export class EventHubAuthRuleListStep extends AzureWizardPromptStep < IEventHubWizardContext > { public async prompt ( context ) { const namespaceName = nonNullProp ( context , 'namespaceName' ) ; const resourceGroupName = nonNullProp ( context , 'resourceGroupName' ) ; const eventHubName = nonNullProp ( context , 'eventhubname' ) ; const client = await createEventHubClient ( context ) ; const namespaceDescription = localize ( 'namespacePolicy' , '(namespace policy)' ) ; const hubDescription = localize ( 'hubPolicy' , '(hub policy)' ) ; async function getEventHubAuthRules ( ) { const namespaceRules = await client . namespaces . listAuthorizationRules ( resourceGroupName , namespaceName ) ; namespaceRules . forEach ( ( r ) => r . _description = namespaceDescription ) ; const hubRules = await client . eventHubs . listAuthorizationRules ( resourceGroupName , namespaceName , eventHubName ) ; hubRules . forEach ( ( r ) => r . _description = hubDescription ) ; return hubRules . concat ( namespaceRules ) ; } const placeHolder = localize ( 'placeHolder' , 'Select an event hub policy' ) ; const result = await promptForResource ( context , placeHolder , getEventHubAuthRules ( ) ) ; if ( result ) { context . authRuleName = nonNullProp ( result , 'name' ) ; context . isNamespaceAuthRule = result . _description === namespaceDescription ; } } public shouldPrompt ( context ) { return ! ! context . namespaceName && ! ! context . eventhubname && ! context . authRuleName ; } }