@@ -442,8 +442,19 @@ function createSchemaByPartitionKeyPath(path, documents = []) {
442442}
443443
444444const setUpDocumentClient = connectionInfo => {
445- const dbName = connectionInfo . azureCosmosdbAccount ;
446- const endpoint = `https://${ dbName } .documents.azure.com/` ;
445+ const getHttpsEndpoint = info => {
446+ // For backward compatibility with previously generated connections
447+ if ( info . gremlinEndpoint ) {
448+ const dbNameRegExp = / w s s : \/ \/ ( \S * ) .g r e m l i n \. c o s m o s \. / i;
449+ const dbName = dbNameRegExp . exec ( info . gremlinEndpoint ) ;
450+
451+ return `https://${ dbName [ 1 ] } .documents.azure.com:443/` ;
452+ } else {
453+ return `https://${ info ?. azureCosmosdbAccount } .documents.azure.com/` ;
454+ }
455+ } ;
456+
457+ const endpoint = getHttpsEndpoint ( connectionInfo ) ;
447458 const key = connectionInfo . accountKey ;
448459
449460 return new CosmosClient ( { endpoint, key } ) ;
@@ -586,14 +597,19 @@ async function getAdditionalAccountInfo(connectionInfo, logger) {
586597 logger . log ( 'info' , { } , 'Account additional info' , connectionInfo . hiddenKeys ) ;
587598
588599 try {
589- const {
590- clientId,
591- appSecret,
592- tenantId,
593- subscriptionId,
594- resourceGroupName,
595- azureCosmosdbAccount : accountName ,
596- } = connectionInfo ;
600+ const { clientId, appSecret, tenantId, subscriptionId, resourceGroupName } = connectionInfo ;
601+
602+ const getAccountName = info => {
603+ if ( info . azureCosmosdbAccount ) {
604+ return info . azureCosmosdbAccount ;
605+ }
606+
607+ // For backward compatibility
608+ const accNameRegex = / w s s : \/ \/ ( .+ ) \. g r e m l i n .+ / i;
609+ const { gremlinEndpoint } = info ;
610+ return accNameRegex . test ( gremlinEndpoint ) ? accNameRegex . exec ( gremlinEndpoint ) [ 1 ] : '' ;
611+ } ;
612+
597613 const tokenBaseURl = `https://login.microsoftonline.com/${ tenantId } /oauth2/token` ;
598614 const { data : tokenData } = await axios ( {
599615 method : 'post' ,
@@ -608,6 +624,7 @@ async function getAdditionalAccountInfo(connectionInfo, logger) {
608624 'Content-Type' : 'application/x-www-form-urlencoded' ,
609625 } ,
610626 } ) ;
627+ const accountName = getAccountName ( connectionInfo ) ;
611628 const dbAccountBaseUrl = `https://management.azure.com/subscriptions/${ subscriptionId } /resourceGroups/${ resourceGroupName } /providers/Microsoft.DocumentDB/databaseAccounts/${ accountName } ?api-version=2015-04-08` ;
612629 const { data : accountData } = await axios ( {
613630 method : 'get' ,
0 commit comments