-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
680 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,8 @@ export default class ConnectionController { | |
private _currentConnectionId: null | string = null; | ||
|
||
_connectionAttempt: null | ConnectionAttempt = null; | ||
_connectionStringInputCancellationToken: null | vscode.CancellationTokenSource = | ||
null; | ||
private _connectingConnectionId: null | string = null; | ||
private _disconnecting = false; | ||
|
||
|
@@ -144,33 +146,44 @@ export default class ConnectionController { | |
|
||
log.info('connectWithURI command called'); | ||
|
||
const cancellationToken = new vscode.CancellationTokenSource(); | ||
this._connectionStringInputCancellationToken = cancellationToken; | ||
|
||
try { | ||
connectionString = await vscode.window.showInputBox({ | ||
value: '', | ||
ignoreFocusOut: true, | ||
placeHolder: | ||
'e.g. mongodb+srv://username:[email protected]/admin', | ||
prompt: 'Enter your connection string (SRV or standard)', | ||
validateInput: (uri: string) => { | ||
if ( | ||
!uri.startsWith('mongodb://') && | ||
!uri.startsWith('mongodb+srv://') | ||
) { | ||
return 'MongoDB connection strings begin with "mongodb://" or "mongodb+srv://"'; | ||
} | ||
connectionString = await vscode.window.showInputBox( | ||
{ | ||
value: '', | ||
ignoreFocusOut: true, | ||
placeHolder: | ||
'e.g. mongodb+srv://username:[email protected]/admin', | ||
prompt: 'Enter your connection string (SRV or standard)', | ||
validateInput: (uri: string) => { | ||
if ( | ||
!uri.startsWith('mongodb://') && | ||
!uri.startsWith('mongodb+srv://') | ||
) { | ||
return 'MongoDB connection strings begin with "mongodb://" or "mongodb+srv://"'; | ||
} | ||
|
||
try { | ||
// eslint-disable-next-line no-new | ||
new ConnectionString(uri); | ||
} catch (error) { | ||
return formatError(error).message; | ||
} | ||
try { | ||
// eslint-disable-next-line no-new | ||
new ConnectionString(uri); | ||
} catch (error) { | ||
return formatError(error).message; | ||
} | ||
|
||
return null; | ||
return null; | ||
}, | ||
}, | ||
}); | ||
cancellationToken.token | ||
); | ||
} catch (e) { | ||
return false; | ||
} finally { | ||
if (this._connectionStringInputCancellationToken === cancellationToken) { | ||
this._connectionStringInputCancellationToken.dispose(); | ||
this._connectionStringInputCancellationToken = null; | ||
} | ||
} | ||
|
||
if (!connectionString) { | ||
|
@@ -255,6 +268,7 @@ export default class ConnectionController { | |
return this._connect(connection.id, connectionType); | ||
} | ||
|
||
// eslint-disable-next-line complexity | ||
async _connect( | ||
connectionId: string, | ||
connectionType: ConnectionTypes | ||
|
@@ -321,22 +335,27 @@ export default class ConnectionController { | |
browserCommandForOIDCAuth: undefined, // We overwrite this below. | ||
}, | ||
}); | ||
const browserAuthCommand = vscode.workspace | ||
.getConfiguration('mdb') | ||
.get('browserCommandForOIDCAuth'); | ||
dataService = await connectionAttempt.connect({ | ||
...connectionOptions, | ||
oidc: { | ||
...cloneDeep(connectionOptions.oidc), | ||
openBrowser: async ({ signal, url }) => { | ||
try { | ||
await openLink(url); | ||
} catch (err) { | ||
if (signal.aborted) return; | ||
// If opening the link fails we default to regular link opening. | ||
await vscode.commands.executeCommand( | ||
'vscode.open', | ||
vscode.Uri.parse(url) | ||
); | ||
} | ||
}, | ||
openBrowser: browserAuthCommand | ||
? { command: browserAuthCommand } | ||
: async ({ signal, url }) => { | ||
try { | ||
await openLink(url); | ||
} catch (err) { | ||
if (signal.aborted) return; | ||
// If opening the link fails we default to regular link opening. | ||
await vscode.commands.executeCommand( | ||
'vscode.open', | ||
vscode.Uri.parse(url) | ||
); | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
|
@@ -410,6 +429,7 @@ export default class ConnectionController { | |
); | ||
|
||
if (removeConfirmationResponse !== 'Confirm') { | ||
await this.disconnect(); | ||
throw new Error('Reauthentication declined by user'); | ||
} | ||
} | ||
|
@@ -733,6 +753,10 @@ export default class ConnectionController { | |
this.eventEmitter.removeListener(eventType, listener); | ||
} | ||
|
||
closeConnectionStringInput() { | ||
this._connectionStringInputCancellationToken?.cancel(); | ||
} | ||
|
||
isConnecting(): boolean { | ||
return !!this._connectionAttempt; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env node | ||
/* eslint-disable */ | ||
'use strict'; | ||
const fetch = require('node-fetch'); | ||
|
||
// fetch() an URL and ignore the response body | ||
(async function () { | ||
(await fetch(process.argv[2])).body?.resume(); | ||
})().catch((err) => { | ||
process.nextTick(() => { | ||
throw err; | ||
}); | ||
}); |
Oops, something went wrong.