Skip to content

Commit cf30c68

Browse files
authored
Remove accounts in account store with no keys (#18016)
* add fix to remove accounts in account store with no keys * add pruneAccounts function * run azureController.removeAccount
1 parent 66b2257 commit cf30c68

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/azure/accountStore.ts

+13
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ export class AccountStore {
6868
}
6969
}
7070

71+
public async pruneAccounts(): Promise<void> {
72+
let configValues = this.getAccounts();
73+
configValues = configValues.filter((val) => {
74+
if (val.key) {
75+
return true;
76+
} else {
77+
return false;
78+
}
79+
});
80+
await this._context.globalState.update(Constants.configAzureAccount, configValues);
81+
return;
82+
}
83+
7184
public async clearAccounts(): Promise<void> {
7285
let configValues = [];
7386
await this._context.globalState.update(Constants.configAzureAccount, configValues);

src/controllers/connectionManager.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1156,9 +1156,14 @@ export default class ConnectionManager {
11561156
return prompter.prompt<IAccount>(questions, true).then(async answers => {
11571157
if (answers?.account) {
11581158
try {
1159-
this._accountStore.removeAccount(answers.account.key.id);
1159+
if (answers.account.key) {
1160+
this._accountStore.removeAccount(answers.account.key.id);
1161+
} else {
1162+
await this._accountStore.pruneAccounts();
1163+
}
11601164
this.azureController.removeAccount(answers.account);
11611165
this.vscodeWrapper.showInformationMessage(LocalizedConstants.accountRemovedSuccessfully);
1166+
11621167
} catch (e) {
11631168
this.vscodeWrapper.showErrorMessage(Utils.formatString(LocalizedConstants.accountRemovalFailed, e.message));
11641169
}

0 commit comments

Comments
 (0)