Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring connection management #18684

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions localization/xliff/vscode-mssql.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,9 @@
<trans-unit id="mssql.connect">
<source xml:lang="en">Connect</source>
</trans-unit>
<trans-unit id="mssql.connectionGroups">
<source xml:lang="en">Connection groups</source>
</trans-unit>
<trans-unit id="mssql.connections">
<source xml:lang="en">Connection profiles defined in &apos;User Settings&apos; are shown under &apos;MS SQL: Connect&apos; command in the command palette.</source>
</trans-unit>
Expand Down Expand Up @@ -1884,12 +1887,33 @@
<trans-unit id="mssql.startQueryHistoryCapture">
<source xml:lang="en">Start Query History Capture</source>
</trans-unit>
<trans-unit id="mssql.connectionGroup.color">
<source xml:lang="en">The color of the connection group.</source>
</trans-unit>
<trans-unit id="mssql.connectionGroup.description">
<source xml:lang="en">The description of the connection group.</source>
</trans-unit>
<trans-unit id="mssql.maxRecentConnections">
<source xml:lang="en">The maximum number of recently used connections to store in the connection list.</source>
</trans-unit>
<trans-unit id="mssql.connectionGroup.name">
<source xml:lang="en">The name of the connection group.</source>
</trans-unit>
<trans-unit id="mssql.objectExplorer.expandTimeout">
<source xml:lang="en">The timeout in seconds for expanding a node in Object Explorer. The default value is 45 seconds.</source>
</trans-unit>
<trans-unit id="mssql.connection.groupId">
<source xml:lang="en">The unique identifier for the connection group this connection profile belongs to.</source>
</trans-unit>
<trans-unit id="mssql.connectionGroup.id">
<source xml:lang="en">The unique identifier for the connection group.</source>
</trans-unit>
<trans-unit id="mssql.connectionGroup.parentId">
<source xml:lang="en">The unique identifier for the parent connection group.</source>
</trans-unit>
<trans-unit id="mssql.connection.id">
<source xml:lang="en">The unique identifier for this connection profile.</source>
</trans-unit>
<trans-unit id="mssql.toggleSqlCmd">
<source xml:lang="en">Toggle SQLCMD Mode</source>
</trans-unit>
Expand Down
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1028,12 +1028,49 @@
"description": "%mssql.maxRecentConnections%",
"scope": "window"
},
"mssql.connectionGroups": {
"type": "array",
"description": "%mssql.connectionGroups%",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "%mssql.connectionGroup.name%"
},
"id": {
"type": "string",
"description": "%mssql.connectionGroup.id%"
},
"color": {
"type": ["string", null],
"description": "%mssql.connectionGroup.color%"
},
"description": {
"type": ["string", null],
"description": "%mssql.connectionGroup.description%"
},
"parentId": {
"type": ["string", null],
"description": "%mssql.connectionGroup.parentId%"
}
}
}
},
"mssql.connections": {
"type": "array",
"description": "%mssql.connections%",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "%mssql.connection.id%"
},
"groupId": {
"type": "string",
"description": "%mssql.connection.groupId%"
},
"server": {
"type": "string",
"default": "{{put-server-name-here}}",
Expand Down
8 changes: 8 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"mssql.logDebugInfo":"[Optional] Log debug output to the VS Code console (Help -> Toggle Developer Tools)",
"mssql.maxRecentConnections":"The maximum number of recently used connections to store in the connection list.",
"mssql.connections":"Connection profiles defined in 'User Settings' are shown under 'MS SQL: Connect' command in the command palette.",
"mssql.connectionGroups":"Connection groups",
"mssql.connection.server":"[Required] Specify the server name to connect to. Use 'hostname instance' or '<server>.database.windows.net' for Azure SQL Database.",
"mssql.connection.database":"[Optional] Specify the database name to connect to. If database is not specified, the default user database setting is used, typically 'master'.",
"mssql.connection.user":"[Optional] Specify the user name for SQL Server authentication. If user name is not specified, when you connect, you will be asked again.",
Expand Down Expand Up @@ -80,6 +81,13 @@
"mssql.connection.profileName":"[Optional] Specify a custom name for this connection profile to easily browse and search in the command palette of Visual Studio Code.",
"mssql.connection.savePassword":"[Optional] When set to 'true', the password for SQL Server authentication is saved in the secure store of your operating system such as KeyChain in MacOS or Secure Store in Windows.",
"mssql.connection.emptyPasswordInput":"[Optional] Indicates whether this profile has an empty password explicitly set",
"mssql.connection.id":"The unique identifier for this connection profile.",
"mssql.connection.groupId":"The unique identifier for the connection group this connection profile belongs to.",
"mssql.connectionGroup.name":"The name of the connection group.",
"mssql.connectionGroup.id":"The unique identifier for the connection group.",
"mssql.connectionGroup.color":"The color of the connection group.",
"mssql.connectionGroup.description":"The description of the connection group.",
"mssql.connectionGroup.parentId":"The unique identifier for the parent connection group.",
"mssql.enableSqlAuthenticationProvider":"Enables use of the Sql Authentication Provider for 'Microsoft Entra Id Interactive' authentication mode when user selects 'AzureMFA' authentication. This enables Server-side resource endpoint integration when fetching access tokens. This option is only supported for 'MSAL' Authentication Library. Please restart Visual Studio Code after changing this option.",
"mssql.enableConnectionPooling":"Enables connection pooling to improve overall connectivity performance. This setting is enabled by default. Visual Studio Code is required to be relaunched when the value is changed. To clear pooled connections, run the command: 'MS SQL: Clear Pooled Connections'",
"mssql.shortcuts":"Shortcuts related to the results window",
Expand Down
8 changes: 4 additions & 4 deletions src/azure/azureController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export abstract class AzureController {
): Promise<void> {
if (
session?.account &&
AzureController.isTokenInValid(
!AzureController.isTokenValid(
session.token!.token,
session.token!.expiresOn,
)
Expand All @@ -245,12 +245,12 @@ export abstract class AzureController {
}

/**
* Returns true if token is invalid or expired
* Returns false if token is invalid or expired
* @param token Token
* @param token expiry
*/
public static isTokenInValid(token: string, expiresOn?: number): boolean {
return !token || AzureController.isTokenExpired(expiresOn);
public static isTokenValid(token: string, expiresOn?: number): boolean {
return !!token && !AzureController.isTokenExpired(expiresOn);
}

/**
Expand Down
29 changes: 12 additions & 17 deletions src/connectionconfig/connectionDialogWebviewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ import { getErrorMessage } from "../utils/utils";
import { l10n } from "vscode";
import {
CredentialsQuickPickItemType,
IConnectionCredentialsQuickPickItem,
IConnectionProfile,
IConnectionProfileWithSource,
} from "../models/interfaces";
import { IAccount } from "../models/contracts/azure";
import {
Expand Down Expand Up @@ -561,24 +561,18 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
savedConnections: IConnectionDialogProfile[];
recentConnections: IConnectionDialogProfile[];
}> {
const unsortedConnections: IConnectionCredentialsQuickPickItem[] =
this._mainController.connectionManager.connectionStore.loadAllConnections(
true /* addRecentConnections */,
const unsortedConnections: IConnectionProfileWithSource[] =
this._mainController.connectionManager.connectionStore.readAllConnections(
true /* includeRecentConnections */,
);

const savedConnections = unsortedConnections
.filter(
(c) =>
c.quickPickItemType ===
CredentialsQuickPickItemType.Profile,
)
.map((c) => c.connectionCreds);
const savedConnections = unsortedConnections.filter(
(c) => c.profileSource === CredentialsQuickPickItemType.Profile,
);

const recentConnections = unsortedConnections
.filter(
(c) => c.quickPickItemType === CredentialsQuickPickItemType.Mru,
)
.map((c) => c.connectionCreds);
const recentConnections = unsortedConnections.filter(
(c) => c.profileSource === CredentialsQuickPickItemType.Mru,
);

sendActionEvent(
TelemetryViews.ConnectionDialog,
Expand Down Expand Up @@ -1002,10 +996,11 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
account,
undefined,
);
const isTokenExpired = AzureController.isTokenInValid(
const isTokenExpired = !AzureController.isTokenValid(
session.token,
session.expiresOn,
);

if (isTokenExpired) {
actionButtons.push({
label: refreshTokenLabel,
Expand Down
Loading
Loading