import { EventHubManagementClient , EventHubManagementModels } from '@azure/arm-eventhub' ; import { createEventHubClient } from '../../../../utils/azureClients' ; import { nonNullProp } from '../../../../utils/nonNull' ; import { IBindingWizardContext } from '../../IBindingWizardContext' ; import { AzureConnectionCreateStepBase , IConnection } from '../AzureConnectionCreateStepBase' ; import { IEventHubWizardContext } from './IEventHubWizardContext' ; export class EventHubConnectionCreateStep extends AzureConnectionCreateStepBase < IEventHubWizardContext & IBindingWizardContext > { public async getConnection ( context ) { const namespaceName = nonNullProp ( context , 'namespaceName' ) ; const resourceGroupName = nonNullProp ( context , 'resourceGroupName' ) ; const eventHubName = nonNullProp ( context , 'eventhubname' ) ; const authRuleName = nonNullProp ( context , 'authRuleName' ) ; const client = await createEventHubClient ( context ) ; let connectionString ; if ( context . isNamespaceAuthRule ) { const keys = await client . namespaces . listKeys ( resourceGroupName , namespaceName , authRuleName ) ; connectionString = `${ nonNullProp ( keys , 'primaryConnectionString' ) };EntityPath=${ eventHubName }` ; } else { const keys = await client . eventHubs . listKeys ( resourceGroupName , namespaceName , eventHubName , authRuleName ) ; connectionString = nonNullProp ( keys , 'primaryConnectionString' ) ; } return { name : `${ namespaceName }_${ authRuleName }` , connectionString } ; } public shouldExecute ( context ) { return ! ! context . namespaceName && ! ! context . eventhubname && ! ! context . authRuleName ; } }