mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 17:23:40 -05:00
Connection management service updates to support multiple providers (#9698)
* Connection management service work * Fix tests * Change how accounts are deleted * Be consistent with names * feedback * Fix based on feedback * Change sqltoolsservice version
This commit is contained in:
@@ -206,6 +206,13 @@ export class AccountManagementService implements IAccountManagementService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all the accounts registered with ADS.
|
||||
*/
|
||||
public getAccounts(): Thenable<azdata.Account[]> {
|
||||
return this._accountStore.getAllAccounts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a security token by asking the account's provider
|
||||
* @param account Account to generate security token for
|
||||
@@ -225,35 +232,49 @@ export class AccountManagementService implements IAccountManagementService {
|
||||
* removed, false otherwise.
|
||||
*/
|
||||
public removeAccount(accountKey: azdata.AccountKey): Thenable<boolean> {
|
||||
let self = this;
|
||||
|
||||
// Step 1) Remove the account
|
||||
// Step 2) Clear the sensitive data from the provider (regardless of whether the account was removed)
|
||||
// Step 3) Update the account cache and fire an event
|
||||
return this.doWithProvider(accountKey.providerId, provider => {
|
||||
return this._accountStore.remove(accountKey)
|
||||
.then(result => {
|
||||
provider.provider.clear(accountKey);
|
||||
return result;
|
||||
})
|
||||
.then(result => {
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
return this.doWithProvider(accountKey.providerId, async provider => {
|
||||
const result = await this._accountStore.remove(accountKey);
|
||||
await provider.provider.clear(accountKey);
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
let indexToRemove: number = firstIndex(provider.accounts, account => {
|
||||
return account.key.accountId === accountKey.accountId;
|
||||
});
|
||||
let indexToRemove: number = firstIndex(provider.accounts, account => {
|
||||
return account.key.accountId === accountKey.accountId;
|
||||
});
|
||||
|
||||
if (indexToRemove >= 0) {
|
||||
provider.accounts.splice(indexToRemove, 1);
|
||||
self.fireAccountListUpdate(provider, false);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
if (indexToRemove >= 0) {
|
||||
provider.accounts.splice(indexToRemove, 1);
|
||||
this.fireAccountListUpdate(provider, false);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all registered accounts
|
||||
*/
|
||||
public async removeAccounts(): Promise<boolean> {
|
||||
const accounts = await this.getAccounts();
|
||||
if (accounts.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let finalResult = true;
|
||||
for (const account of accounts) {
|
||||
const removeResult = await this.removeAccount(account.key);
|
||||
if (removeResult === false) {
|
||||
this.logService.info('Error when removing %s.', account.key);
|
||||
finalResult = false;
|
||||
}
|
||||
}
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
// UI METHODS //////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Opens the account list dialog
|
||||
|
||||
Reference in New Issue
Block a user