import { CosmosDBManagementClient , CosmosDBManagementModels } from '@azure/arm-cosmosdb' ; import { getResourceGroupFromId } from '../../../../utils/azure' ; import { createCosmosDBClient } from '../../../../utils/azureClients' ; import { nonNullProp } from '../../../../utils/nonNull' ; import { IBindingWizardContext } from '../../IBindingWizardContext' ; import { AzureConnectionCreateStepBase , IConnection } from '../AzureConnectionCreateStepBase' ; import { ICosmosDBWizardContext } from './ICosmosDBWizardContext' ; export class CosmosDBConnectionCreateStep extends AzureConnectionCreateStepBase < IBindingWizardContext & ICosmosDBWizardContext > { public async getConnection ( context ) { const databaseAccount = nonNullProp ( context , 'databaseAccount' ) ; const name = nonNullProp ( databaseAccount , 'name' ) ; const client = await createCosmosDBClient ( context ) ; const resourceGroup = getResourceGroupFromId ( nonNullProp ( databaseAccount , 'id' ) ) ; const keys = await client . databaseAccounts . listKeys ( resourceGroup , name ) ; return { name : name , connectionString : `AccountEndpoint=${ nonNullProp ( databaseAccount , 'documentEndpoint' ) };AccountKey=${ nonNullProp ( keys , 'primaryMasterKey' ) };` } ; } public shouldExecute ( context ) { return ! ! context . databaseAccount ; } }