Add default auth type configuration setting for Azure resources (#16999)

* Adding user config for default auth type

* adding feature

* removing the SqlLogin default from the model

* fixing bug, removing dead code

* removing unneeded instance of configurationService

* fixing line break

* removing extra parameter

* removing comments

* Fix test breaks

* Fix build break

* More breaks

* Address code review feedback

Co-authored-by: Troy Witthoeft <troy.witthoeft@gmail.com>
This commit is contained in:
Karl Burtram
2021-09-07 19:58:32 -07:00
committed by GitHub
parent e9c48da4b7
commit 73ee6c3844
9 changed files with 67 additions and 3 deletions

View File

@@ -152,6 +152,16 @@ export class ConnectionDialogService implements IConnectionDialogService {
return defaultProvider || Constants.mssqlProviderName;
}
private getDefaultAuthenticationTypeName(): string {
let defaultAuthenticationType: string;
if (!defaultAuthenticationType && this._configurationService) {
defaultAuthenticationType = WorkbenchUtils.getSqlConfigValue<string>(this._configurationService, Constants.defaultAuthenticationType);
}
return defaultAuthenticationType || Constants.sqlLogin; // as a fallback, default to sql login if the value from settings is not available
}
private handleOnConnect(params: INewConnectionParams, profile?: IConnectionProfile): void {
this._logService.debug('ConnectionDialogService: onConnect event is received');
if (!this._connecting) {
@@ -383,6 +393,14 @@ export class ConnectionDialogService implements IConnectionDialogService {
if (model && !model.providerName) {
model.providerName = providerName;
}
const defaultAuthenticationType = this.getDefaultAuthenticationTypeName();
let authenticationTypeName = model ? model.authenticationType : defaultAuthenticationType;
authenticationTypeName = authenticationTypeName ? authenticationTypeName : defaultAuthenticationType;
if (model && !model.authenticationType) {
model.authenticationType = authenticationTypeName;
}
let newProfile = new ConnectionProfile(this._capabilitiesService, model || providerName);
newProfile.saveProfile = true;
newProfile.generateNewId();

View File

@@ -306,6 +306,11 @@ export class ConnectionManagementService extends Disposable implements IConnecti
// Fill in the Azure account token if needed and open the connection dialog if it fails
let tokenFillSuccess = await this.fillInOrClearToken(newConnection);
// If there is no authentication type set, set it using configuration
if (!newConnection.authenticationType || newConnection.authenticationType === '') {
newConnection.authenticationType = this.getDefaultAuthenticationTypeId();
}
// If the password is required and still not loaded show the dialog
if ((!foundPassword && this._connectionStore.isPasswordRequired(newConnection) && !newConnection.password) || !tokenFillSuccess) {
return this.showConnectionDialogOnError(connection, owner, { connected: false, errorMessage: undefined, callStack: undefined, errorCode: undefined }, options);
@@ -792,6 +797,11 @@ export class ConnectionManagementService extends Disposable implements IConnecti
return defaultProvider && this._providers.has(defaultProvider) ? defaultProvider : undefined;
}
public getDefaultAuthenticationTypeId(): string {
let defaultAuthenticationType = WorkbenchUtils.getSqlConfigValue<string>(this._configurationService, Constants.defaultAuthenticationType);
return defaultAuthenticationType;
}
/**
* Previously, the only resource available for AAD access tokens was for Azure SQL / SQL Server.
* Use that as a default if the provider extension does not configure a different one. If one is