mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-13 17:22:15 -05:00
Support migrating credentials to new format (#23088)
This commit is contained in:
@@ -9,7 +9,7 @@ import { ConnectionConfig } from 'sql/platform/connection/common/connectionConfi
|
||||
import { fixupConnectionCredentials } from 'sql/platform/connection/common/connectionInfo';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ConnectionProfileGroup, IConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import { AuthenticationType } from 'sql/platform/connection/common/constants';
|
||||
import { AuthenticationType, mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { IConnectionProfile, ProfileMatcher } from 'sql/platform/connection/common/interfaces';
|
||||
import { ICredentialsService } from 'sql/platform/credentials/common/credentialsService';
|
||||
import { isDisposable } from 'vs/base/common/lifecycle';
|
||||
@@ -84,10 +84,28 @@ export class ConnectionStore {
|
||||
if (credentialsItem.savePassword && this.isPasswordRequired(credentialsItem) && !credentialsItem.password) {
|
||||
const credentialId = this.formatCredentialId(credentialsItem, CRED_PROFILE_USER);
|
||||
return this.credentialService.readCredential(credentialId)
|
||||
.then(savedCred => {
|
||||
if (savedCred) {
|
||||
.then(async savedCred => {
|
||||
if (savedCred?.password) {
|
||||
credentialsItem.password = savedCred.password;
|
||||
credentialsItem.options['password'] = savedCred.password;
|
||||
} else if (credentialsItem.providerName === mssqlProviderName) {
|
||||
// Special handling for MSSQL provider as "applicationName:azdata" is no longer included
|
||||
// in credential string starting with MAY 2023 release.
|
||||
// We will try to read credential including applicationName and if it is found,
|
||||
// we will update the saved credential with new credential key.
|
||||
// This special case handling should be removed in a future release.
|
||||
let credParts = credentialId.split('|');
|
||||
credParts.splice(3, 0, 'applicationName:azdata');
|
||||
const oldCredentialId = credParts.join('|');
|
||||
const savedMssqlCred = await this.credentialService.readCredential(oldCredentialId);
|
||||
if (savedMssqlCred?.password) {
|
||||
credentialsItem.password = savedMssqlCred.password;
|
||||
credentialsItem.options['password'] = savedMssqlCred.password;
|
||||
// Update credential in credential store.
|
||||
await this.credentialService.deleteCredential(oldCredentialId);
|
||||
await this.credentialService.saveCredential(credentialId, savedMssqlCred.password);
|
||||
savedCred.password = savedMssqlCred.password;
|
||||
}
|
||||
}
|
||||
return { profile: credentialsItem, savedCred: !!savedCred };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user