mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-31 09:35:39 -05:00
Allow 'ApplicationName' to be specified for MSSQL connections (#22890)
This commit is contained in:
2
src/sql/azdata.d.ts
vendored
2
src/sql/azdata.d.ts
vendored
@@ -2879,7 +2879,7 @@ declare module 'azdata' {
|
||||
* @param title The title shown in the editor tab
|
||||
* @param options Options to configure the editor
|
||||
* @param name The name used to identify the editor in telemetry
|
||||
*/
|
||||
*/
|
||||
export function createModelViewEditor(title: string, options?: ModelViewEditorOptions, name?: string): ModelViewEditor;
|
||||
|
||||
export interface ModelViewEditor extends window.ModelViewPanel {
|
||||
|
||||
@@ -13,6 +13,7 @@ import { isString } from 'vs/base/common/types';
|
||||
import { deepClone } from 'vs/base/common/objects';
|
||||
import * as Constants from 'sql/platform/connection/common/constants';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { adjustForMssqlAppName } from 'sql/platform/connection/common/utils';
|
||||
|
||||
export interface IconPath {
|
||||
light: URI;
|
||||
@@ -65,10 +66,17 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
|
||||
let capabilities = this.capabilitiesService.getCapabilities(this.providerName);
|
||||
if (capabilities && capabilities.connection && capabilities.connection.connectionOptions) {
|
||||
const options = capabilities.connection.connectionOptions;
|
||||
// MSSQL Provider doesn't treat appName as special type anymore.
|
||||
let appNameOption = options.find(option => option.specialValueType === interfaces.ConnectionOptionSpecialType.appName);
|
||||
if (appNameOption) {
|
||||
let appNameKey = appNameOption.name;
|
||||
this.options[appNameKey] = Constants.applicationName;
|
||||
} else if (this.providerName === Constants.mssqlProviderName || this.providerName === Constants.mssqlCmsProviderName) {
|
||||
// Update AppName here for MSSQL and MSSQL-CMS provider to be able to match connection URI with STS.
|
||||
appNameOption = options.find(option => option.name === Constants.mssqlApplicationNameOption);
|
||||
if (appNameOption) {
|
||||
this.options[Constants.mssqlApplicationNameOption] = adjustForMssqlAppName(model.options[Constants.mssqlApplicationNameOption]);
|
||||
}
|
||||
}
|
||||
// Set values for advanced options received in model.
|
||||
Object.keys(model.options).forEach(a => {
|
||||
|
||||
@@ -11,12 +11,14 @@ export const outputChannelName = 'MSSQL';
|
||||
export const capabilitiesOptions = 'OPTIONS_METADATA';
|
||||
|
||||
export const mssqlProviderName = 'MSSQL';
|
||||
export const mssqlCmsProviderName = 'MSSQL-CMS';
|
||||
export const mysqlProviderName = 'MYSQL';
|
||||
export const pgsqlProviderName = 'PGSQL';
|
||||
export const anyProviderName = '*';
|
||||
export const connectionProviderContextKey = 'connectionProvider';
|
||||
|
||||
export const applicationName = 'azdata';
|
||||
export const mssqlApplicationNameOption = 'applicationName';
|
||||
|
||||
export const defaultEngine = 'defaultEngine';
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import * as sqlExtHostTypes from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { applicationName } from 'sql/platform/connection/common/constants';
|
||||
|
||||
// CONSTANTS //////////////////////////////////////////////////////////////////////////////////////
|
||||
const msInH = 3.6e6;
|
||||
@@ -170,3 +171,11 @@ export function convertToRpcConnectionProfile(profile: IConnectionProfile | unde
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
export function adjustForMssqlAppName(currentAppName: string, suffix?: string): string {
|
||||
let appName = suffix ? applicationName + '-' + suffix : applicationName;
|
||||
let finalSuffix = '-' + appName;
|
||||
return (currentAppName && currentAppName !== appName && !currentAppName.endsWith(finalSuffix))
|
||||
? currentAppName + finalSuffix
|
||||
: currentAppName ?? appName;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ export interface SqlArgs {
|
||||
aad?: boolean; // deprecated - used by SSMS - authenticationType should be used instead
|
||||
integrated?: boolean; // deprecated - used by SSMS - authenticationType should be used instead.
|
||||
showDashboard?: boolean;
|
||||
applicationName?: string;
|
||||
}
|
||||
|
||||
//#region decorators
|
||||
@@ -307,7 +308,10 @@ export class CommandLineWorkbenchContribution implements IWorkbenchContribution,
|
||||
Constants.AuthenticationType.Integrated;
|
||||
|
||||
profile.connectionName = '';
|
||||
profile.setOptionValue('applicationName', Constants.applicationName);
|
||||
const applicationName = args.applicationName
|
||||
? args.applicationName + '-' + Constants.applicationName
|
||||
: Constants.applicationName;
|
||||
profile.setOptionValue('applicationName', applicationName);
|
||||
profile.setOptionValue('databaseDisplayName', profile.databaseName);
|
||||
profile.setOptionValue('groupId', profile.groupId);
|
||||
return this._connectionManagementService ? this.tryMatchSavedProfile(profile) : profile;
|
||||
|
||||
@@ -95,6 +95,7 @@ class TestParsedArgs implements NativeParsedArgs, SqlArgs {
|
||||
wait?: boolean;
|
||||
waitMarkerFilePath?: string;
|
||||
authenticationType?: string;
|
||||
applicationName?: string;
|
||||
}
|
||||
suite('commandLineService tests', () => {
|
||||
|
||||
@@ -196,12 +197,14 @@ suite('commandLineService tests', () => {
|
||||
args.database = 'mydatabase';
|
||||
args.user = 'myuser';
|
||||
args.authenticationType = Constants.AuthenticationType.SqlLogin;
|
||||
args.applicationName = 'myapplication';
|
||||
|
||||
connectionManagementService.setup((c) => c.showConnectionDialog()).verifiable(TypeMoq.Times.never());
|
||||
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => true).verifiable(TypeMoq.Times.atMostOnce());
|
||||
connectionManagementService.setup(c => c.getConnectionGroups(TypeMoq.It.isAny())).returns(() => []);
|
||||
let originalProfile: IConnectionProfile = undefined;
|
||||
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.is<ConnectionProfile>(p => p.serverName === 'myserver' && p.authenticationType === Constants.AuthenticationType.SqlLogin), 'connection', true))
|
||||
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.is<ConnectionProfile>(
|
||||
p => p.serverName === 'myserver' && p.authenticationType === Constants.AuthenticationType.SqlLogin && p.options['applicationName'] === 'myapplication-azdata'), 'connection', true))
|
||||
.returns((conn) => {
|
||||
originalProfile = conn;
|
||||
return Promise.resolve('unused');
|
||||
@@ -212,6 +215,7 @@ suite('commandLineService tests', () => {
|
||||
const logService = new NullLogService();
|
||||
let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object, capabilitiesService, undefined, undefined, logService);
|
||||
await contribution.processCommandLine(args);
|
||||
assert.equal(originalProfile.options['applicationName'], 'myapplication-azdata', 'Application Name not received as expected.');
|
||||
connectionManagementService.verifyAll();
|
||||
});
|
||||
|
||||
|
||||
@@ -160,10 +160,16 @@ export class ConnectionController implements IConnectionComponentController {
|
||||
this._connectionWidget.updateServerGroup(this.getAllServerGroups(providers));
|
||||
this._model = connectionInfo;
|
||||
this._model.providerName = this._providerName;
|
||||
// MSSQL and MSSQL-CMS Provider don't treat appName as special type anymore.
|
||||
let appNameOption = this._providerOptions.find(option => option.specialValueType === ConnectionOptionSpecialType.appName);
|
||||
if (appNameOption) {
|
||||
let appNameKey = appNameOption.name;
|
||||
this._model.options[appNameKey] = Constants.applicationName;
|
||||
} else {
|
||||
appNameOption = this._providerOptions.find(option => option.name === Constants.mssqlApplicationNameOption);
|
||||
if (appNameOption && (this._model.providerName === Constants.mssqlProviderName || this._model.providerName === Constants.mssqlCmsProviderName)) {
|
||||
this._model.options[Constants.mssqlApplicationNameOption] = Utils.adjustForMssqlAppName(this._model.options[Constants.mssqlApplicationNameOption]);
|
||||
}
|
||||
}
|
||||
this._connectionWidget.initDialog(this._model);
|
||||
}
|
||||
|
||||
@@ -38,10 +38,11 @@ import { ConnectionStringOptions } from 'sql/platform/capabilities/common/capabi
|
||||
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { filterAccounts } from 'sql/workbench/services/accountManagement/browser/accountDialog';
|
||||
import { AuthenticationType, Actions } from 'sql/platform/connection/common/constants';
|
||||
import { AuthenticationType, Actions, mssqlApplicationNameOption, applicationName, mssqlProviderName, mssqlCmsProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { AdsWidget } from 'sql/base/browser/ui/adsWidget';
|
||||
import { createCSSRule } from 'vs/base/browser/dom';
|
||||
import { AuthLibrary, getAuthLibrary } from 'sql/workbench/services/accountManagement/utils';
|
||||
import { adjustForMssqlAppName } from 'sql/platform/connection/common/utils';
|
||||
|
||||
const ConnectionStringText = localize('connectionWidget.connectionString', "Connection string");
|
||||
|
||||
@@ -1253,6 +1254,11 @@ export class ConnectionWidget extends lifecycle.Disposable {
|
||||
});
|
||||
}
|
||||
}
|
||||
// Fix Application Name for MSSQL/MSSQL-CMS Providers, to handle special case as we need to apply custom application name in ADS Core connection profile.
|
||||
if ((model.providerName === mssqlProviderName || model.providerName === mssqlCmsProviderName)
|
||||
&& model.options[mssqlApplicationNameOption] && !model.options[mssqlApplicationNameOption].endsWith(applicationName)) {
|
||||
model.options[mssqlApplicationNameOption] = adjustForMssqlAppName(model.options[mssqlApplicationNameOption]);
|
||||
}
|
||||
model.connectionName = this.connectionName;
|
||||
if (this._serverGroupSelectBox) {
|
||||
if (this._serverGroupSelectBox.value === this.DefaultServerGroup.name) {
|
||||
|
||||
Reference in New Issue
Block a user