Skip to content

Commit 05426de

Browse files
committed
add getting account information
1 parent 2a53e57 commit 05426de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+6412
-125
lines changed

reverse_engineering/api.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const async = require('async');
44
const _ = require('lodash');
55
const { CosmosClient } = require('@azure/cosmos');
6+
const axios = require('axios');
67
const gremlinHelper = require('./gremlinHelper');
78
let client;
89

@@ -93,9 +94,11 @@ module.exports = {
9394
relationships: []
9495
};
9596
const { resource: accountInfo } = await client.getDatabaseAccount();
97+
const additionalAccountInfo = await getAdditionalAccountInfo(data, logger);
9698
const modelInfo = {
9799
defaultConsistency: accountInfo.consistencyPolicy,
98100
preferredLocation: accountInfo.writableLocations[0] ? accountInfo.writableLocations[0].name : '',
101+
...additionalAccountInfo,
99102
};
100103

101104
const dbCollectionsPromise = collectionNames.map(async collectionName => {
@@ -497,3 +500,68 @@ function getTTL(defaultTTL) {
497500
}
498501
return defaultTTL === -1 ? 'On (no default)' : 'On';
499502
}
503+
504+
async function getAdditionalAccountInfo(connectionInfo, logger) {
505+
if (connectionInfo.disableSSL || !connectionInfo.includeAccountInformation) {
506+
return {};
507+
}
508+
509+
logger.log('info', {}, 'Account additional info', connectionInfo.hiddenKeys);
510+
511+
try {
512+
const { clientId, appSecret, tenantId, subscriptionId, resourceGroupName, host } = connectionInfo;
513+
const accNameRegex = /wss:\/\/(.+)\.gremlinEndpoint.+/i;
514+
const accountName = accNameRegex.test(host) ? accNameRegex.exec(host)[1] : '';
515+
const tokenBaseURl = `https://login.microsoftonline.com/${tenantId}/oauth2/token`;
516+
const { data: tokenData } = await axios({
517+
method: 'post',
518+
url: tokenBaseURl,
519+
data: qs.stringify({
520+
grant_type: 'client_credentials',
521+
client_id: clientId,
522+
client_secret: appSecret,
523+
resource: 'https://management.azure.com/'
524+
}),
525+
headers: {
526+
'Content-Type': 'application/x-www-form-urlencoded'
527+
}
528+
});
529+
const dbAccountBaseUrl = `https://management.azure.com/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}?api-version=2015-04-08`;
530+
const { data: accountData } = await axios({
531+
method: 'get',
532+
url: dbAccountBaseUrl,
533+
headers: {
534+
'Authorization': `${tokenData.token_type} ${tokenData.access_token}`
535+
}
536+
});
537+
logger.progress({
538+
message: 'Getting account information',
539+
containerName: connectionInfo.database,
540+
entityName: ''
541+
});
542+
return {
543+
enableMultipleWriteLocations: accountData.properties.enableMultipleWriteLocations,
544+
enableAutomaticFailover: accountData.properties.enableAutomaticFailover,
545+
isVirtualNetworkFilterEnabled: accountData.properties.isVirtualNetworkFilterEnabled,
546+
virtualNetworkRules: accountData.properties.virtualNetworkRules.map(({ id, ignoreMissingVNetServiceEndpoint }) => ({
547+
virtualNetworkId: id,
548+
ignoreMissingVNetServiceEndpoint
549+
})),
550+
ipRangeFilter: accountData.properties.ipRangeFilter,
551+
tags: Object.entries(accountData.tags).map(([tagName, tagValue]) => ({ tagName, tagValue })),
552+
locations: accountData.properties.locations.map(({ id, locationName, failoverPriority, isZoneRedundant }) => ({
553+
locationId: id,
554+
locationName,
555+
failoverPriority,
556+
isZoneRedundant
557+
}))
558+
};
559+
} catch(err) {
560+
logger.log('error', { message: _.get(err, 'response.data.error.message', err.message), stack: err.stack });
561+
logger.progress({
562+
message: 'Error while getting account information',
563+
containerName: connectionInfo.database
564+
});
565+
return {};
566+
}
567+
}

reverse_engineering/connection_settings_modal/connectionSettingsModalConfig.json

Lines changed: 37 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"inputKeyword": "name",
88
"inputType": "text",
99
"inputPlaceholder": "Name",
10+
"inputTooltip": "Choose a friendly connection name",
1011
"validation": {
1112
"regex": "([^\\s])"
1213
}
@@ -17,6 +18,7 @@
1718
"inputKeyword": "gremlinEndpoint",
1819
"inputType": "text",
1920
"inputPlaceholder": "wss://*.gremlin.cosmos.azure.com:443/",
21+
"inputTooltip": "Paste Gremlin endpoint",
2022
"defaultValue": "",
2123
"validation": {
2224
"regex": "([^\\s])"
@@ -25,9 +27,10 @@
2527
{
2628
"inputLabel": "Account key",
2729
"inputKeyword": "accountKey",
28-
"inputType": "text",
30+
"inputType": "password",
2931
"inputPlaceholder": "",
3032
"defaultValue": "",
33+
"inputTooltip": "Paste the account Primary or Secondary (Read-Only) Key",
3134
"isHiddenKey": true,
3235
"validation": {
3336
"regex": "([^\\s])"
@@ -36,154 +39,63 @@
3639
]
3740
},
3841
{
39-
"tab": "SSL",
42+
"tab": "Control Plane parameters",
4043
"structure": [
4144
{
42-
"inputLabel": "SSL",
43-
"inputKeyword": "sslType",
44-
"inputType": "select",
45-
"options": [{
46-
"value": "Off",
47-
"label": "Off"
48-
}, {
49-
"value": "TRUST_ALL_CERTIFICATES",
50-
"label": "Unvalidated"
51-
},{
52-
"value": "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES",
53-
"label": "Server validation"
54-
55-
},{
56-
"value": "TRUST_SERVER_CLIENT_CERTIFICATES",
57-
"label": "Server and client validation"
58-
},{
59-
"value": "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES",
60-
"label": "SYSTEMCA"
61-
}]
62-
},
63-
{
64-
"inputLabel": "Certificate Authority",
65-
"inputKeyword": "certAuthority",
66-
"inputType": "file",
67-
"inputPlaceholder": "Certificate Authority",
68-
"extensions": ["pem", "crt", "key"],
69-
"dependency": {
70-
"key": "sslType",
71-
"value": ["TRUST_CUSTOM_CA_SIGNED_CERTIFICATES", "TRUST_SERVER_CLIENT_CERTIFICATES"]
72-
}
73-
},
74-
{
75-
"inputLabel": "PFX",
76-
"inputKeyword": "pfx",
77-
"inputType": "file",
78-
"inputPlaceholder": "PFX or PKCS12 encoded private key and certificate chain",
79-
"extensions": ["pfx"],
80-
"dependency": {
81-
"key": "sslType",
82-
"value": "TRUST_SERVER_CLIENT_CERTIFICATES"
83-
}
84-
}
85-
]
86-
},
87-
{
88-
"tab": "SSH",
89-
"structure": [
90-
{
91-
"inputLabel": "Use SSH Tunnel",
92-
"inputKeyword": "ssh",
45+
"inputLabel": "Enable REST API connection",
46+
"inputKeyword": "includeAccountInformation",
9347
"inputType": "checkbox",
94-
"defaultValue": false
48+
"inputTooltip": "Check this box if you want to include Cosmos DB account information"
9549
},
9650
{
97-
"inputLabel": "SSH Address",
98-
"inputKeyword": "ssh_host",
51+
"inputLabel": "Resource group name",
52+
"inputKeyword": "resourceGroupName",
9953
"inputType": "text",
100-
"inputPlaceholder": "SSH Address",
101-
"disable": {
102-
"key": "ssh",
103-
"value": false
104-
}
105-
},
106-
{
107-
"inputLabel": "Port",
108-
"inputKeyword": "ssh_port",
109-
"inputType": "numeric",
110-
"inputPlaceholder": "Port",
111-
"defaultValue": 22,
112-
"disable": {
113-
"key": "ssh",
114-
"value": false
54+
"inputTooltip": "Specify the Resource group name from the Overview screen of the Cosmos DB instance",
55+
"dependency": {
56+
"key": "includeAccountInformation",
57+
"value": [true, "true"]
11558
}
11659
},
11760
{
118-
"inputLabel": "SSH User Name",
119-
"inputKeyword": "ssh_user",
61+
"inputLabel": "Subscription ID",
62+
"inputKeyword": "subscriptionId",
12063
"inputType": "text",
121-
"inputPlaceholder": "SSH User Name",
122-
"disable": {
123-
"key": "ssh",
124-
"value": false
64+
"inputTooltip": "Specify the Subscription ID from the Overview screen of the Cosmos DB instance",
65+
"dependency": {
66+
"key": "includeAccountInformation",
67+
"value": [true, "true"]
12568
}
12669
},
12770
{
128-
"inputLabel": "SSH Auth Method",
129-
"inputKeyword": "ssh_method",
130-
"inputType": "select",
131-
"options": [{
132-
"value": "privateKey",
133-
"label": "Private Key"
134-
}, {
135-
"value": "password",
136-
"label": "Password"
137-
}],
138-
"disable": {
139-
"key": "ssh",
140-
"value": false
141-
},
142-
"defaultValue": "privateKey"
143-
},
144-
{
145-
"inputLabel": "Private Key",
146-
"inputKeyword": "ssh_key_file",
147-
"inputType": "file",
148-
"inputPlaceholder": "Private Key",
149-
"extensions": ["*"],
71+
"inputLabel": "Application (client) ID",
72+
"inputKeyword": "clientId",
73+
"inputType": "text",
74+
"inputTooltip": "Azure Active Directory application id from the Overview screen of the App registration",
15075
"dependency": {
151-
"key": "ssh_method",
152-
"value": ["privateKey", ""]
153-
},
154-
"disable": {
155-
"key": "ssh",
156-
"value": false
76+
"key": "includeAccountInformation",
77+
"value": [true, "true"]
15778
}
15879
},
15980
{
160-
"inputLabel": "Passphrase",
161-
"inputKeyword": "ssh_key_passphrase",
162-
"inputType": "password",
163-
"inputPlaceholder": "Passphrase",
164-
"isHiddenKey": true,
81+
"inputLabel": "Directory (tenant) ID",
82+
"inputKeyword": "tenantId",
83+
"inputType": "text",
84+
"inputTooltip": "Specify the Directory (tenant) ID from the Overview screen of the App registration",
16585
"dependency": {
166-
"key": "ssh_method",
167-
"value": ["privateKey", ""]
168-
},
169-
"disable": {
170-
"key": "ssh",
171-
"value": false
86+
"key": "includeAccountInformation",
87+
"value": [true, "true"]
17288
}
17389
},
17490
{
175-
"inputLabel": "Client key password",
176-
"inputKeyword": "ssh_password",
91+
"inputLabel": "Application secret",
92+
"inputKeyword": "appSecret",
17793
"inputType": "password",
178-
"inputPlaceholder": "Password",
94+
"inputTooltip": "Specify the Application secret string",
17995
"isHiddenKey": true,
18096
"dependency": {
181-
"key": "ssh_method",
182-
"value": ["password", ""]
183-
},
184-
"disable": {
185-
"key": "ssh",
186-
"value": false
97+
"key": "includeAccountInformation",
98+
"value": [true, "true"]
18799
}
188100
}
189101
]

0 commit comments

Comments
 (0)