import { ServiceBusManagementClient , ServiceBusManagementModels } from '@azure/arm-servicebus' ; import { localize } from '../../../../localize' ; import { getResourceGroupFromId } from '../../../../utils/azure' ; import { createServiceBusClient } from '../../../../utils/azureClients' ; import { nonNullProp } from '../../../../utils/nonNull' ; import { IBindingWizardContext } from '../../IBindingWizardContext' ; import { AzureConnectionCreateStepBase , IConnection } from '../AzureConnectionCreateStepBase' ; import { IServiceBusWizardContext } from './IServiceBusWizardContext' ; export class ServiceBusConnectionCreateStep extends AzureConnectionCreateStepBase < IServiceBusWizardContext & IBindingWizardContext > { public async getConnection ( context ) { const sbNamespace = nonNullProp ( context , 'sbNamespace' ) ; const id = nonNullProp ( sbNamespace , 'id' ) ; const name = nonNullProp ( sbNamespace , 'name' ) ; const resourceGroup = getResourceGroupFromId ( id ) ; const client = await createServiceBusClient ( context ) ; const authRules = await client . namespaces . listAuthorizationRules ( resourceGroup , name ) ; const authRule = authRules . find ( ar => ar . rights . some ( r => r . toLowerCase ( ) === 'listen' ) ) ; if ( ! authRule ) { throw new Error ( localize ( 'noAuthRule' , 'Failed to get connection string for service bus namespace "{0}".' , name ) ) ; } const keys = await client . namespaces . listKeys ( resourceGroup , name , nonNullProp ( authRule , 'name' ) ) ; return { name : name , connectionString : nonNullProp ( keys , 'primaryConnectionString' ) } ; } public shouldExecute ( context ) { return ! ! context . sbNamespace ; } }