Allow 'ApplicationName' to be specified for MSSQL connections (#22890)

This commit is contained in:
Cheena Malhotra
2023-05-01 10:55:05 -07:00
committed by GitHub
parent f4952c76b8
commit ea6bb41f45
12 changed files with 81 additions and 39 deletions

View File

@@ -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;

View File

@@ -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();
});

View File

@@ -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);
}

View File

@@ -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) {