@@ -2,42 +2,9 @@ import * as vscode from 'vscode';
2
2
3
3
import ConnectionController from '../connectionController' ;
4
4
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
-
37
5
const launchMongoDBShellWithEnv = (
38
6
shellCommand : string ,
39
7
mdbConnectionString : string ,
40
- mdbSslOptions : string [ ] ,
41
8
envVariableString : string
42
9
) => {
43
10
const mongoDBShell = vscode . window . createTerminal ( {
@@ -47,51 +14,41 @@ const launchMongoDBShellWithEnv = (
47
14
}
48
15
} ) ;
49
16
50
- const mdbSslOptionsString = mdbSslOptions . length > 0
51
- ? `${ mdbSslOptions . join ( ' ' ) } `
52
- : '' ;
53
-
54
17
mongoDBShell . sendText (
55
- `${ shellCommand } ${ mdbSslOptionsString } ${ envVariableString } ;`
18
+ `${ shellCommand } ${ envVariableString } ;`
56
19
) ;
57
20
mongoDBShell . show ( ) ;
58
21
} ;
59
22
60
23
const launchMongoDBShellOnPowershell = (
61
24
shellCommand : string ,
62
- mdbConnectionString : string ,
63
- mdbSslOptions : string [ ]
25
+ mdbConnectionString : string
64
26
) : void => {
65
- launchMongoDBShellWithEnv ( shellCommand , mdbConnectionString , mdbSslOptions , '$Env:MDB_CONNECTION_STRING' ) ;
27
+ launchMongoDBShellWithEnv ( shellCommand , mdbConnectionString , '$Env:MDB_CONNECTION_STRING' ) ;
66
28
} ;
67
29
68
30
const launchMongoDBShellOnCmd = (
69
31
shellCommand : string ,
70
- mdbConnectionString : string ,
71
- mdbSslOptions : string [ ]
32
+ mdbConnectionString : string
72
33
) : void => {
73
- launchMongoDBShellWithEnv ( shellCommand , mdbConnectionString , mdbSslOptions , '%MDB_CONNECTION_STRING%' ) ;
34
+ launchMongoDBShellWithEnv ( shellCommand , mdbConnectionString , '%MDB_CONNECTION_STRING%' ) ;
74
35
} ;
75
36
76
37
const launchMongoDBShellOnGitBash = (
77
38
shellCommand : string ,
78
- mdbConnectionString : string ,
79
- mdbSslOptions : string [ ]
39
+ mdbConnectionString : string
80
40
) : void => {
81
- launchMongoDBShellWithEnv ( shellCommand , mdbConnectionString , mdbSslOptions , '$MDB_CONNECTION_STRING' ) ;
41
+ launchMongoDBShellWithEnv ( shellCommand , mdbConnectionString , '$MDB_CONNECTION_STRING' ) ;
82
42
} ;
83
43
84
44
const launchMongoDBShellOnBash = (
85
45
shellCommand : string ,
86
- mdbConnectionString : string ,
87
- mdbSslOptions : string [ ]
46
+ mdbConnectionString : string
88
47
) : void => {
89
- launchMongoDBShellWithEnv ( shellCommand , mdbConnectionString , mdbSslOptions , '$MDB_CONNECTION_STRING' ) ;
48
+ launchMongoDBShellWithEnv ( shellCommand , mdbConnectionString , '$MDB_CONNECTION_STRING' ) ;
90
49
} ;
91
50
92
51
const openMongoDBShell = ( connectionController : ConnectionController ) : Promise < boolean > => {
93
- let mdbSslOptions : string [ ] = [ ] ;
94
-
95
52
if (
96
53
! connectionController . isCurrentlyConnected ( )
97
54
) {
@@ -120,28 +77,28 @@ const openMongoDBShell = (connectionController: ConnectionController): Promise<b
120
77
return Promise . resolve ( false ) ;
121
78
}
122
79
123
- const activeConnectionModel = connectionController
124
- . getActiveConnectionModel ( )
125
- ?. getAttributes ( { derived : true } ) ;
80
+ const activeMongoClientOptions = connectionController . getMongoClientConnectionOptions ( ) ;
126
81
127
- const mdbConnectionString = activeConnectionModel
128
- ? activeConnectionModel . driverUrlWithSsh
129
- : '' ;
82
+ if ( ! activeMongoClientOptions ) {
83
+ void vscode . window . showErrorMessage (
84
+ 'No active connection found.'
85
+ ) ;
130
86
131
- if ( activeConnectionModel && isSslConnection ( activeConnectionModel ) ) {
132
- mdbSslOptions = getSslOptions ( activeConnectionModel . driverOptions ) ;
87
+ return Promise . resolve ( false ) ;
133
88
}
134
89
90
+ const mdbConnectionString = activeMongoClientOptions . url || '' ;
91
+
135
92
if ( userShell . includes ( 'powershell.exe' ) ) {
136
- launchMongoDBShellOnPowershell ( shellCommand , mdbConnectionString , mdbSslOptions ) ;
93
+ launchMongoDBShellOnPowershell ( shellCommand , mdbConnectionString ) ;
137
94
} else if ( userShell . includes ( 'cmd.exe' ) ) {
138
- launchMongoDBShellOnCmd ( shellCommand , mdbConnectionString , mdbSslOptions ) ;
95
+ launchMongoDBShellOnCmd ( shellCommand , mdbConnectionString ) ;
139
96
} else if ( userShell . toLocaleLowerCase ( ) . includes ( 'git\\bin\\bash.exe' ) ) {
140
- launchMongoDBShellOnGitBash ( shellCommand , mdbConnectionString , mdbSslOptions ) ;
97
+ launchMongoDBShellOnGitBash ( shellCommand , mdbConnectionString ) ;
141
98
} else {
142
99
// Assume it's a bash environment. This may fail on certain
143
100
// shells but should cover most cases.
144
- launchMongoDBShellOnBash ( shellCommand , mdbConnectionString , mdbSslOptions ) ;
101
+ launchMongoDBShellOnBash ( shellCommand , mdbConnectionString ) ;
145
102
}
146
103
147
104
return Promise . resolve ( true ) ;
0 commit comments