mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -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 { fixupConnectionCredentials } from 'sql/platform/connection/common/connectionInfo';
|
||||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||||
import { ConnectionProfileGroup, IConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
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 { IConnectionProfile, ProfileMatcher } from 'sql/platform/connection/common/interfaces';
|
||||||
import { ICredentialsService } from 'sql/platform/credentials/common/credentialsService';
|
import { ICredentialsService } from 'sql/platform/credentials/common/credentialsService';
|
||||||
import { isDisposable } from 'vs/base/common/lifecycle';
|
import { isDisposable } from 'vs/base/common/lifecycle';
|
||||||
@@ -84,10 +84,28 @@ export class ConnectionStore {
|
|||||||
if (credentialsItem.savePassword && this.isPasswordRequired(credentialsItem) && !credentialsItem.password) {
|
if (credentialsItem.savePassword && this.isPasswordRequired(credentialsItem) && !credentialsItem.password) {
|
||||||
const credentialId = this.formatCredentialId(credentialsItem, CRED_PROFILE_USER);
|
const credentialId = this.formatCredentialId(credentialsItem, CRED_PROFILE_USER);
|
||||||
return this.credentialService.readCredential(credentialId)
|
return this.credentialService.readCredential(credentialId)
|
||||||
.then(savedCred => {
|
.then(async savedCred => {
|
||||||
if (savedCred) {
|
if (savedCred?.password) {
|
||||||
credentialsItem.password = savedCred.password;
|
credentialsItem.password = savedCred.password;
|
||||||
credentialsItem.options['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 };
|
return { profile: credentialsItem, savedCred: !!savedCred };
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user