From fc963e08d51b5cb3f40f61a04741e7c0df434c12 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Mon, 10 Jul 2023 23:48:13 -0700 Subject: [PATCH 1/3] Fix connection string related issues --- src/models/connectionCredentials.ts | 14 +++++++++++--- src/models/connectionStore.ts | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/models/connectionCredentials.ts b/src/models/connectionCredentials.ts index 3fd1474f92..6313d60b91 100644 --- a/src/models/connectionCredentials.ts +++ b/src/models/connectionCredentials.ts @@ -252,7 +252,15 @@ export class ConnectionCredentials implements IConnectionInfo { } } }, - default: defaultProfileValues ? await connectionStore.lookupPassword(defaultProfileValues) : undefined + default: async defaultProfileValues => { + if (defaultProfileValues.connectionString) { + if ((defaultProfileValues as IConnectionProfile).savePassword) { + // look up connection string + let connectionString = await connectionStore.lookupPassword(defaultProfileValues, true); + defaultProfileValues.connectionString = connectionString; + } + } else return await connectionStore.lookupPassword(defaultProfileValues); + } } ]; return questions; @@ -298,8 +306,8 @@ export class ConnectionCredentials implements IConnectionInfo { public static isPasswordBasedConnectionString(connectionString: string): boolean { const connString = connectionString.toLowerCase(); - return connString.includes('user') && - connString.includes('password') && + return (connString.includes('user') || connString.includes('uid') || connString.includes('userid')) && + (connString.includes('password') || connString.includes('pwd')) && !connString.includes('Integrated Security'); } diff --git a/src/models/connectionStore.ts b/src/models/connectionStore.ts index cc1cf9dcb5..d9535f68cc 100644 --- a/src/models/connectionStore.ts +++ b/src/models/connectionStore.ts @@ -72,7 +72,7 @@ export class ConnectionStore { * @returns {string} formatted string with server, DB and username */ public static formatCredentialId(server: string, database?: string, user?: string, itemType?: string, isConnectionString?: boolean): string { - if (Utils.isEmpty(server)) { + if (Utils.isEmpty(server) && !isConnectionString) { throw new ValidationException('Missing Server Name, which is required'); } let cred: string[] = [ConnectionStore.CRED_PREFIX]; From d588b7cfb3e72b1a88fb9e737f8ffbe8240fe37c Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Tue, 11 Jul 2023 00:32:44 -0700 Subject: [PATCH 2/3] Fix picklist description to be user friendly --- src/models/connectionInfo.ts | 25 +++++++------------------ src/models/connectionStore.ts | 2 +- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/models/connectionInfo.ts b/src/models/connectionInfo.ts index 9d9d60b48a..e3b3a5cb2c 100644 --- a/src/models/connectionInfo.ts +++ b/src/models/connectionInfo.ts @@ -6,7 +6,7 @@ import { IConnectionInfo, IServerInfo } from 'vscode-mssql'; import * as Constants from '../constants/constants'; import * as LocalizedConstants from '../constants/localizedConstants'; -import { EncryptOptions, IConnectionProfile } from '../models/interfaces'; +import { EncryptOptions } from '../models/interfaces'; import * as Interfaces from './interfaces'; import * as Utils from './utils'; @@ -137,25 +137,14 @@ export function getPicklistDetails(connCreds: IConnectionInfo): string { */ export function getConnectionDisplayString(creds: IConnectionInfo): string { // Update the connection text - let text: string; - if (creds.connectionString) { - // If a connection string is present, try to display the profile name - if ((creds).profileName) { - text = (creds).profileName; - text = appendIfNotEmpty(text, creds.connectionString); - } else { - text = creds.connectionString; - } + let text: string = creds.server; + if (creds.database !== '') { + text = appendIfNotEmpty(text, creds.database); } else { - text = creds.server; - if (creds.database !== '') { - text = appendIfNotEmpty(text, creds.database); - } else { - text = appendIfNotEmpty(text, LocalizedConstants.defaultDatabaseLabel); - } - let user: string = getUserNameOrDomainLogin(creds); - text = appendIfNotEmpty(text, user); + text = appendIfNotEmpty(text, LocalizedConstants.defaultDatabaseLabel); } + let user: string = getUserNameOrDomainLogin(creds); + text = appendIfNotEmpty(text, user); // Limit the maximum length of displayed text if (text.length > Constants.maxDisplayedStatusTextLength) { diff --git a/src/models/connectionStore.ts b/src/models/connectionStore.ts index d9535f68cc..59ed1fcb4f 100644 --- a/src/models/connectionStore.ts +++ b/src/models/connectionStore.ts @@ -116,7 +116,7 @@ export class ConnectionStore { * @returns {Promise} */ public getPickListItems(): IConnectionCredentialsQuickPickItem[] { - let pickListItems: IConnectionCredentialsQuickPickItem[] = this.loadAllConnections(true); + let pickListItems: IConnectionCredentialsQuickPickItem[] = this.loadAllConnections(false); pickListItems.push({ label: `$(add) ${LocalizedConstants.CreateProfileFromConnectionsListLabel}`, connectionCreds: undefined, From 48c1e9d546b9e09d3f8c7bbe4094615bcc2cb019 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Tue, 11 Jul 2023 00:35:45 -0700 Subject: [PATCH 3/3] lint --- src/models/connectionCredentials.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/models/connectionCredentials.ts b/src/models/connectionCredentials.ts index 6313d60b91..dbca77250b 100644 --- a/src/models/connectionCredentials.ts +++ b/src/models/connectionCredentials.ts @@ -252,14 +252,16 @@ export class ConnectionCredentials implements IConnectionInfo { } } }, - default: async defaultProfileValues => { - if (defaultProfileValues.connectionString) { - if ((defaultProfileValues as IConnectionProfile).savePassword) { + default: async (value) => { + if (value.connectionString) { + if ((value as IConnectionProfile).savePassword) { // look up connection string - let connectionString = await connectionStore.lookupPassword(defaultProfileValues, true); - defaultProfileValues.connectionString = connectionString; + let connectionString = await connectionStore.lookupPassword(value, true); + value.connectionString = connectionString; } - } else return await connectionStore.lookupPassword(defaultProfileValues); + } else { + return await connectionStore.lookupPassword(value); + } } } ];