Skip to content

Commit 4941766

Browse files
committed
Add backward compatibility
1 parent 580b40b commit 4941766

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

reverse_engineering/api.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,19 @@ function createSchemaByPartitionKeyPath(path, documents = []) {
442442
}
443443

444444
const 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 = /wss:\/\/(\S*).gremlin\.cosmos\./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 = /wss:\/\/(.+)\.gremlin.+/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',

reverse_engineering/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"excludeDocKind": ["id"],
77
"scenario": "getDatabases",
88
"connectionList": ["name", "azureCosmosdbAccount"],
9-
"widestColumn": "gremlinEndpoint",
9+
"widestColumn": "azureCosmosdbAccount",
1010
"helpUrl": "https://hackolade.com/help/Azureinstance2.html"
1111
}

reverse_engineering/connection_settings_modal/connectionSettingsModalConfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
}
1414
},
1515
{
16-
"inputLabel": "Azure Cosmos DB Account",
16+
"inputLabel": "Azure Cosmos DB Account name",
1717
"inputKeyword": "azureCosmosdbAccount",
1818
"inputType": "text",
1919
"inputPlaceholder": "",
20-
"inputTooltip": "Paste the Azure Cosmos DB account",
20+
"inputTooltip": "Paste the Azure Cosmos DB account name",
2121
"defaultValue": "",
2222
"validation": [
2323
{
@@ -32,7 +32,7 @@
3232
"inputType": "password",
3333
"inputPlaceholder": "",
3434
"defaultValue": "",
35-
"inputTooltip": "Paste the account Primary or Secondary (Read-Only) Key",
35+
"inputTooltip": "Paste the account Primary or Secondary (Read-Only if doing only RE but FE will require write rights) Key",
3636
"isHiddenKey": true
3737
}
3838
]

reverse_engineering/gremlinHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const connectToInstance = info => {
1919
const traversalSource = 'g';
2020
const databaseName = info.database || database;
2121
const accountKeyString = info.accountKey || accountKey;
22-
gremlinEndpoint = `wss://${info.azureCosmosdbAccount}.gremlin.cosmos.azure.com`;
22+
gremlinEndpoint = info?.gremlinEndpoint || `wss://${info.azureCosmosdbAccount}.gremlin.cosmos.azure.com`;
2323

2424
persistConnectionInfo(info);
2525

0 commit comments

Comments
 (0)