Skip to content

Commit ff15215

Browse files
refactor: new data service and connection model VSCODE-311 (#377)
* refactor: switch to new data service and connection model VSCODE-312 * feat: handle secrets and migrate old connections VSCODE-313, VSCODE-314 * fix: set default objects for storages * test: mock connection model * refactor: use mongodb-connection-string-url instead of connectionModel.from * fix: keep all connection options from new connection model * refactor: give connectionString to users to copy instead of driverUrlWithSsh * refactor: use getMongoClientConnectionOptions to launch shell * refactor: adress pr comments * refactor: code style cleaning up * refactor: pull secrets methods from data service * refactor: convertConnectionModelToInfo accepts raw models now * fix: copy connection string without appname * fix: do not repeat indexes error for each expand action in the sidebar * fix: change kerberosCanonicalizeHostname to boolean
1 parent 6e7111b commit ff15215

File tree

60 files changed

+1887
-4178
lines changed

Some content is hidden

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

60 files changed

+1887
-4178
lines changed

.vscode/settings.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,5 @@
1717
"out": true
1818
},
1919
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
20-
"typescript.tsc.autoDetect": "off",
21-
// Language server logging for
22-
// https://github.com/Microsoft/language-server-protocol-inspector
23-
"mongodbLanguageServer.trace.server": {
24-
"format": "json",
25-
"verbosity": "verbose"
26-
}
20+
"typescript.tsc.autoDetect": "off"
2721
}

package-lock.json

Lines changed: 417 additions & 1607 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,6 @@
389389
"light": "images/light/plus-circle.svg",
390390
"dark": "images/dark/plus-circle.svg"
391391
}
392-
},
393-
{
394-
"command": "mdb.startStreamLanguageServerLogs",
395-
"title": "LSP Inspector: Start Stream LSP Logs"
396392
}
397393
],
398394
"menus": {
@@ -923,9 +919,9 @@
923919
"micromatch": "^4.0.4",
924920
"mongodb": "^4.2.0",
925921
"mongodb-cloud-info": "^1.1.3",
926-
"mongodb-connection-model": "^21.5.4",
927-
"mongodb-data-service": "^21.5.4",
928-
"mongodb-js-errors": "^0.5.0",
922+
"mongodb-connection-model": "^21.10.0",
923+
"mongodb-connection-string-url": "^2.4.0",
924+
"mongodb-data-service": "^21.15.0",
929925
"mongodb-ns": "^2.2.0",
930926
"mongodb-schema": "^9.0.0",
931927
"numeral": "^2.0.6",
@@ -937,8 +933,7 @@
937933
"uuid": "^8.3.2",
938934
"vscode-languageclient": "^7.0.0",
939935
"vscode-languageserver": "^7.0.0",
940-
"vscode-languageserver-textdocument": "^1.0.2",
941-
"ws": "^7.5.5"
936+
"vscode-languageserver-textdocument": "^1.0.2"
942937
},
943938
"devDependencies": {
944939
"@types/analytics-node": "^3.1.7",
@@ -958,7 +953,6 @@
958953
"@types/sinon": "^9.0.11",
959954
"@types/uuid": "^8.3.3",
960955
"@types/vscode": "^1.58.1",
961-
"@types/ws": "^7.4.7",
962956
"@typescript-eslint/eslint-plugin": "^4.33.0",
963957
"@typescript-eslint/parser": "^4.33.0",
964958
"autoprefixer": "^9.8.8",

src/commands/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ enum EXTENSION_COMMANDS {
2626

2727
MDB_CHANGE_ACTIVE_CONNECTION = 'mdb.changeActiveConnection',
2828
MDB_REFRESH_PLAYGROUNDS = 'mdb.refreshPlaygrounds',
29-
MDB_START_LANGUAGE_STREAM_LOGS = 'mdb.startStreamLanguageServerLogs',
3029

3130
MDB_CODELENS_SHOW_MORE_DOCUMENTS = 'mdb.codeLens.showMoreDocumentsClicked',
3231

src/commands/launchMongoShell.ts

Lines changed: 21 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,9 @@ import * as vscode from 'vscode';
22

33
import ConnectionController from '../connectionController';
44

5-
const isSslConnection = (activeConnectionModel: any): boolean => {
6-
return !!(
7-
activeConnectionModel &&
8-
activeConnectionModel.driverOptions &&
9-
(activeConnectionModel.driverOptions.sslCA ||
10-
activeConnectionModel.driverOptions.sslCert ||
11-
activeConnectionModel.driverOptions.sslPass)
12-
);
13-
};
14-
15-
const getSslOptions = (driverOptions: any): string[] => {
16-
const mdbSslOptions = ['--tls'];
17-
18-
if (!driverOptions.checkServerIdentity) {
19-
mdbSslOptions.push('--tlsAllowInvalidHostnames');
20-
}
21-
22-
if (driverOptions.sslCA) {
23-
mdbSslOptions.push(`--tlsCAFile="${driverOptions.sslCA}"`);
24-
}
25-
26-
if (driverOptions.sslCert) {
27-
mdbSslOptions.push(`--tlsCertificateKeyFile="${driverOptions.sslCert}"`);
28-
}
29-
30-
if (driverOptions.sslPass) {
31-
mdbSslOptions.push(`--tlsCertificateKeyFilePassword="${driverOptions.sslPass}"`);
32-
}
33-
34-
return mdbSslOptions;
35-
};
36-
375
const launchMongoDBShellWithEnv = (
386
shellCommand: string,
397
mdbConnectionString: string,
40-
mdbSslOptions: string[],
418
envVariableString: string
429
) => {
4310
const mongoDBShell = vscode.window.createTerminal({
@@ -47,51 +14,41 @@ const launchMongoDBShellWithEnv = (
4714
}
4815
});
4916

50-
const mdbSslOptionsString = mdbSslOptions.length > 0
51-
? `${mdbSslOptions.join(' ')} `
52-
: '';
53-
5417
mongoDBShell.sendText(
55-
`${shellCommand} ${mdbSslOptionsString}${envVariableString};`
18+
`${shellCommand} ${envVariableString};`
5619
);
5720
mongoDBShell.show();
5821
};
5922

6023
const launchMongoDBShellOnPowershell = (
6124
shellCommand: string,
62-
mdbConnectionString: string,
63-
mdbSslOptions: string[]
25+
mdbConnectionString: string
6426
): void => {
65-
launchMongoDBShellWithEnv(shellCommand, mdbConnectionString, mdbSslOptions, '$Env:MDB_CONNECTION_STRING');
27+
launchMongoDBShellWithEnv(shellCommand, mdbConnectionString, '$Env:MDB_CONNECTION_STRING');
6628
};
6729

6830
const launchMongoDBShellOnCmd = (
6931
shellCommand: string,
70-
mdbConnectionString: string,
71-
mdbSslOptions: string[]
32+
mdbConnectionString: string
7233
): void => {
73-
launchMongoDBShellWithEnv(shellCommand, mdbConnectionString, mdbSslOptions, '%MDB_CONNECTION_STRING%');
34+
launchMongoDBShellWithEnv(shellCommand, mdbConnectionString, '%MDB_CONNECTION_STRING%');
7435
};
7536

7637
const launchMongoDBShellOnGitBash = (
7738
shellCommand: string,
78-
mdbConnectionString: string,
79-
mdbSslOptions: string[]
39+
mdbConnectionString: string
8040
): void => {
81-
launchMongoDBShellWithEnv(shellCommand, mdbConnectionString, mdbSslOptions, '$MDB_CONNECTION_STRING');
41+
launchMongoDBShellWithEnv(shellCommand, mdbConnectionString, '$MDB_CONNECTION_STRING');
8242
};
8343

8444
const launchMongoDBShellOnBash = (
8545
shellCommand: string,
86-
mdbConnectionString: string,
87-
mdbSslOptions: string[]
46+
mdbConnectionString: string
8847
): void => {
89-
launchMongoDBShellWithEnv(shellCommand, mdbConnectionString, mdbSslOptions, '$MDB_CONNECTION_STRING');
48+
launchMongoDBShellWithEnv(shellCommand, mdbConnectionString, '$MDB_CONNECTION_STRING');
9049
};
9150

9251
const openMongoDBShell = (connectionController: ConnectionController): Promise<boolean> => {
93-
let mdbSslOptions: string[] = [];
94-
9552
if (
9653
!connectionController.isCurrentlyConnected()
9754
) {
@@ -120,28 +77,28 @@ const openMongoDBShell = (connectionController: ConnectionController): Promise<b
12077
return Promise.resolve(false);
12178
}
12279

123-
const activeConnectionModel = connectionController
124-
.getActiveConnectionModel()
125-
?.getAttributes({ derived: true });
80+
const activeMongoClientOptions = connectionController.getMongoClientConnectionOptions();
12681

127-
const mdbConnectionString = activeConnectionModel
128-
? activeConnectionModel.driverUrlWithSsh
129-
: '';
82+
if (!activeMongoClientOptions) {
83+
void vscode.window.showErrorMessage(
84+
'No active connection found.'
85+
);
13086

131-
if (activeConnectionModel && isSslConnection(activeConnectionModel)) {
132-
mdbSslOptions = getSslOptions(activeConnectionModel.driverOptions);
87+
return Promise.resolve(false);
13388
}
13489

90+
const mdbConnectionString = activeMongoClientOptions.url || '';
91+
13592
if (userShell.includes('powershell.exe')) {
136-
launchMongoDBShellOnPowershell(shellCommand, mdbConnectionString, mdbSslOptions);
93+
launchMongoDBShellOnPowershell(shellCommand, mdbConnectionString);
13794
} else if (userShell.includes('cmd.exe')) {
138-
launchMongoDBShellOnCmd(shellCommand, mdbConnectionString, mdbSslOptions);
95+
launchMongoDBShellOnCmd(shellCommand, mdbConnectionString);
13996
} else if (userShell.toLocaleLowerCase().includes('git\\bin\\bash.exe')) {
140-
launchMongoDBShellOnGitBash(shellCommand, mdbConnectionString, mdbSslOptions);
97+
launchMongoDBShellOnGitBash(shellCommand, mdbConnectionString);
14198
} else {
14299
// Assume it's a bash environment. This may fail on certain
143100
// shells but should cover most cases.
144-
launchMongoDBShellOnBash(shellCommand, mdbConnectionString, mdbSslOptions);
101+
launchMongoDBShellOnBash(shellCommand, mdbConnectionString);
145102
}
146103

147104
return Promise.resolve(true);

0 commit comments

Comments
 (0)