mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-29 17:23:25 -05:00
Fix IConnectionProfile to have same options key when generated from ConnectionProfile (#22840)
This commit is contained in:
@@ -284,6 +284,7 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
|
||||
serverName: this.serverName,
|
||||
databaseName: this.databaseName,
|
||||
authenticationType: this.authenticationType,
|
||||
serverCapabilities: this.serverCapabilities,
|
||||
getOptionsKey: this.getOptionsKey,
|
||||
matches: this.matches,
|
||||
groupId: this.groupId,
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
|
||||
// Used to allow various methods of matching profiles
|
||||
export type ProfileMatcher = (a: IConnectionProfile, b: IConnectionProfile) => boolean;
|
||||
|
||||
export interface IConnectionProfile extends azdata.IConnectionProfile {
|
||||
serverCapabilities: ConnectionProviderProperties | undefined;
|
||||
getOptionsKey(getOriginalOptions?: boolean): string;
|
||||
matches(profile: azdata.IConnectionProfile): boolean;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo {
|
||||
this.providerName = isString(model) ? model : 'providerName' in model ? model.providerName : model.providerId;
|
||||
|
||||
if (!isString(model)) {
|
||||
if (model.options && this.hasServerCapabilities()) {
|
||||
if (model.options && this.serverCapabilities) {
|
||||
this.serverCapabilities.connectionOptions.forEach(option => {
|
||||
let value = model.options[option.name];
|
||||
this.options[option.name] = value;
|
||||
@@ -136,7 +136,7 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo {
|
||||
|
||||
private getServerInfo() {
|
||||
let title = '';
|
||||
if (this.hasServerCapabilities()) {
|
||||
if (this.serverCapabilities) {
|
||||
title = this.serverName;
|
||||
// Only show database name if the provider supports it.
|
||||
if (this.serverCapabilities.connectionOptions?.find(option => option.specialValueType === ConnectionOptionSpecialType.databaseName)) {
|
||||
@@ -153,7 +153,7 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo {
|
||||
public get title(): string {
|
||||
let label = '';
|
||||
|
||||
if (this.hasServerCapabilities()) {
|
||||
if (this.serverCapabilities) {
|
||||
if (this.connectionName) {
|
||||
label = this.connectionName;
|
||||
} else {
|
||||
@@ -169,10 +169,6 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo {
|
||||
return label;
|
||||
}
|
||||
|
||||
public hasServerCapabilities(): boolean {
|
||||
return (this.serverCapabilities !== undefined);
|
||||
}
|
||||
|
||||
public hasLoaded(): boolean {
|
||||
return Object.keys(this.capabilitiesService.providers).length > 0;
|
||||
}
|
||||
@@ -187,7 +183,7 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo {
|
||||
|
||||
public isPasswordRequired(): boolean {
|
||||
// if there is no provider capabilities metadata assume a password is not required
|
||||
if (!this.hasServerCapabilities()) {
|
||||
if (!this.serverCapabilities) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -218,7 +214,7 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo {
|
||||
public getOptionsKey(getOriginalOptions?: boolean): string {
|
||||
let useFullOptions = false;
|
||||
let idNames = [];
|
||||
if (this.hasServerCapabilities()) {
|
||||
if (this.serverCapabilities) {
|
||||
useFullOptions = this.serverCapabilities.useFullOptions;
|
||||
idNames = this.serverCapabilities.connectionOptions.map(o => {
|
||||
// All options enabled, use every property besides password.
|
||||
@@ -299,7 +295,7 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo {
|
||||
}
|
||||
|
||||
public getSpecialTypeOptionName(type: string): string | undefined {
|
||||
if (this.hasServerCapabilities()) {
|
||||
if (this.serverCapabilities) {
|
||||
let optionMetadata = this.serverCapabilities.connectionOptions.find(o => o.specialValueType === type);
|
||||
return !!optionMetadata ? optionMetadata.name : undefined;
|
||||
} else {
|
||||
@@ -315,7 +311,7 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo {
|
||||
}
|
||||
|
||||
public get authenticationTypeDisplayName(): string {
|
||||
let optionMetadata = this.hasServerCapabilities() ? this.serverCapabilities.connectionOptions.find(o => o.specialValueType === ConnectionOptionSpecialType.authType) : undefined;
|
||||
let optionMetadata = this.serverCapabilities ? this.serverCapabilities.connectionOptions.find(o => o.specialValueType === ConnectionOptionSpecialType.authType) : undefined;
|
||||
let authType = this.authenticationType;
|
||||
let displayName: string = authType;
|
||||
|
||||
@@ -361,7 +357,7 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo {
|
||||
public getConnectionOptionsList(needSpecial: boolean, getNonDefault: boolean): azdata.ConnectionOption[] {
|
||||
let connectionOptions: azdata.ConnectionOption[] = [];
|
||||
|
||||
if (this.hasServerCapabilities()) {
|
||||
if (this.serverCapabilities) {
|
||||
this.serverCapabilities.connectionOptions.forEach(element => {
|
||||
if (((!needSpecial && element.specialValueType !== ConnectionOptionSpecialType.serverName &&
|
||||
element.specialValueType !== ConnectionOptionSpecialType.databaseName &&
|
||||
|
||||
@@ -301,6 +301,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: undefined,
|
||||
groupId: undefined,
|
||||
getOptionsKey: undefined!,
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -333,6 +334,7 @@ suite('ConnectionConfig', () => {
|
||||
savePassword: true,
|
||||
groupFullName: undefined,
|
||||
getOptionsKey: undefined!,
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -365,6 +367,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: undefined,
|
||||
getOptionsKey: undefined!,
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -508,6 +511,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'g3',
|
||||
groupId: 'g3',
|
||||
getOptionsKey: undefined!,
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -538,6 +542,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'g3',
|
||||
groupId: 'g3',
|
||||
getOptionsKey: undefined!,
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -575,6 +580,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'g3',
|
||||
groupId: 'newid',
|
||||
getOptionsKey: undefined!,
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -655,6 +661,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'g3',
|
||||
groupId: 'g3',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -672,6 +679,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'test',
|
||||
groupId: 'test',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -712,6 +720,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'g3',
|
||||
groupId: 'g3',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {
|
||||
@@ -732,6 +741,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'test',
|
||||
groupId: 'test',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: { 'testProperty2': '15' },
|
||||
@@ -770,6 +780,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'g3',
|
||||
groupId: 'g3',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {
|
||||
@@ -790,6 +801,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'test',
|
||||
groupId: 'test',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: { 'testProperty1': 'nonDefault' },
|
||||
@@ -831,6 +843,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'g3',
|
||||
groupId: 'g3',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {
|
||||
@@ -851,6 +864,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'test',
|
||||
groupId: 'test',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: { 'testProperty2': '15' },
|
||||
@@ -889,6 +903,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'g3',
|
||||
groupId: 'g3',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -991,6 +1006,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'g3',
|
||||
groupId: 'g3',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -1008,6 +1024,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'test',
|
||||
groupId: 'test',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -1025,6 +1042,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'test',
|
||||
groupId: 'test',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -1059,6 +1077,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'test',
|
||||
groupId: 'test',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -1076,6 +1095,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'test',
|
||||
groupId: 'test',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
@@ -1093,6 +1113,7 @@ suite('ConnectionConfig', () => {
|
||||
groupFullName: 'test',
|
||||
groupId: 'test',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
|
||||
@@ -26,6 +26,7 @@ suite('SQL ConnectionProfileInfo tests', () => {
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: undefined!,
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
@@ -282,4 +283,10 @@ suite('SQL ConnectionProfileInfo tests', () => {
|
||||
test('an empty connection profile does not cause issues', () => {
|
||||
assert.doesNotThrow(() => new ConnectionProfile(capabilitiesService, {} as IConnectionProfile));
|
||||
});
|
||||
|
||||
test('getOptionsKey should produce the same optionsKey after converting to IConnectionProfile', () => {
|
||||
let conn = new ConnectionProfile(capabilitiesService, iConnectionProfile);
|
||||
const myIConnectionProfile = conn.toIConnectionProfile();
|
||||
assert.equal(conn.getOptionsKey(), myIConnectionProfile.getOptionsKey());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,6 +32,7 @@ suite('ConnectionStore', () => {
|
||||
groupId: '',
|
||||
groupFullName: '',
|
||||
getOptionsKey: undefined!,
|
||||
serverCapabilities: undefined,
|
||||
matches: () => false,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
|
||||
@@ -25,6 +25,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: undefined,
|
||||
getOptionsKey: undefined!,
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: mssqlProviderName,
|
||||
options: undefined!,
|
||||
|
||||
@@ -27,6 +27,7 @@ let connectionProfile: IConnectionProfile = {
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: () => 'connection1',
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
@@ -44,6 +45,7 @@ let editorConnectionProfile: IConnectionProfile = {
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: () => 'connection2',
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
@@ -61,6 +63,7 @@ let connectionProfileWithoutDbName: IConnectionProfile = {
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: () => 'connection1',
|
||||
serverCapabilities: undefined,
|
||||
matches: undefined!,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
|
||||
Reference in New Issue
Block a user