mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Wait for account provider registration when using account service (#3221)
This commit is contained in:
@@ -6,11 +6,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import * as sqlops from 'sqlops';
|
import * as sqlops from 'sqlops';
|
||||||
import * as nls from 'vs/nls';
|
|
||||||
import * as platform from 'vs/platform/registry/common/platform';
|
import * as platform from 'vs/platform/registry/common/platform';
|
||||||
import * as statusbar from 'vs/workbench/browser/parts/statusbar/statusbar';
|
import * as statusbar from 'vs/workbench/browser/parts/statusbar/statusbar';
|
||||||
|
|
||||||
import { Event, Emitter } from 'vs/base/common/event';
|
import { Event, Emitter } from 'vs/base/common/event';
|
||||||
|
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||||
import { Memento, Scope as MementoScope } from 'vs/workbench/common/memento';
|
import { Memento, Scope as MementoScope } from 'vs/workbench/common/memento';
|
||||||
@@ -20,8 +20,8 @@ import { AccountDialogController } from 'sql/parts/accountManagement/accountDial
|
|||||||
import { AutoOAuthDialogController } from 'sql/parts/accountManagement/autoOAuthDialog/autoOAuthDialogController';
|
import { AutoOAuthDialogController } from 'sql/parts/accountManagement/autoOAuthDialog/autoOAuthDialogController';
|
||||||
import { AccountListStatusbarItem } from 'sql/parts/accountManagement/accountListStatusbar/accountListStatusbarItem';
|
import { AccountListStatusbarItem } from 'sql/parts/accountManagement/accountListStatusbar/accountListStatusbarItem';
|
||||||
import { AccountProviderAddedEventParams, UpdateAccountListEventParams } from 'sql/services/accountManagement/eventTypes';
|
import { AccountProviderAddedEventParams, UpdateAccountListEventParams } from 'sql/services/accountManagement/eventTypes';
|
||||||
import { IAccountManagementService, AzureResource } from 'sql/services/accountManagement/interfaces';
|
import { IAccountManagementService } from 'sql/services/accountManagement/interfaces';
|
||||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
import { Deferred } from 'sql/base/common/promise';
|
||||||
|
|
||||||
export class AccountManagementService implements IAccountManagementService {
|
export class AccountManagementService implements IAccountManagementService {
|
||||||
// CONSTANTS ///////////////////////////////////////////////////////////
|
// CONSTANTS ///////////////////////////////////////////////////////////
|
||||||
@@ -198,11 +198,6 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
public getAccountsForProvider(providerId: string): Thenable<sqlops.Account[]> {
|
public getAccountsForProvider(providerId: string): Thenable<sqlops.Account[]> {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
// Make sure the provider exists before attempting to retrieve accounts
|
|
||||||
if (!this._providers[providerId]) {
|
|
||||||
return Promise.reject(new Error(nls.localize('accountManagementNoProvider', 'Account provider does not exist'))).then();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1) Get the accounts from the store
|
// 1) Get the accounts from the store
|
||||||
// 2) Update our local cache of accounts
|
// 2) Update our local cache of accounts
|
||||||
return this.doWithProvider(providerId, provider => {
|
return this.doWithProvider(providerId, provider => {
|
||||||
@@ -217,7 +212,7 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
/**
|
/**
|
||||||
* Generates a security token by asking the account's provider
|
* Generates a security token by asking the account's provider
|
||||||
* @param {Account} account Account to generate security token for
|
* @param {Account} account Account to generate security token for
|
||||||
* @param {AzureResource} resource The resource to get the security token for
|
* @param {sqlops.AzureResource} resource The resource to get the security token for
|
||||||
* @return {Thenable<{}>} Promise to return the security token
|
* @return {Thenable<{}>} Promise to return the security token
|
||||||
*/
|
*/
|
||||||
public getSecurityToken(account: sqlops.Account, resource: sqlops.AzureResource): Thenable<{}> {
|
public getSecurityToken(account: sqlops.Account, resource: sqlops.AzureResource): Thenable<{}> {
|
||||||
@@ -389,10 +384,17 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
|
|
||||||
// PRIVATE HELPERS /////////////////////////////////////////////////////
|
// PRIVATE HELPERS /////////////////////////////////////////////////////
|
||||||
private doWithProvider<T>(providerId: string, op: (provider: AccountProviderWithMetadata) => Thenable<T>): Thenable<T> {
|
private doWithProvider<T>(providerId: string, op: (provider: AccountProviderWithMetadata) => Thenable<T>): Thenable<T> {
|
||||||
// Make sure the provider exists before attempting to retrieve accounts
|
|
||||||
let provider = this._providers[providerId];
|
let provider = this._providers[providerId];
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
return Promise.reject(new Error(nls.localize('accountManagementNoProvider', 'Account provider does not exist'))).then();
|
// If the provider doesn't already exist wait until it gets registered
|
||||||
|
let deferredPromise = new Deferred<T>();
|
||||||
|
let toDispose = this.addAccountProviderEvent(params => {
|
||||||
|
if (params.addedProvider.id === providerId) {
|
||||||
|
toDispose.dispose();
|
||||||
|
deferredPromise.resolve(op(this._providers[providerId]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return deferredPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
return op(provider);
|
return op(provider);
|
||||||
|
|||||||
@@ -221,13 +221,13 @@ suite('Account Management Service Tests:', () => {
|
|||||||
let ams = getTestState().accountManagementService;
|
let ams = getTestState().accountManagementService;
|
||||||
|
|
||||||
// If: I add an account when the provider doesn't exist
|
// If: I add an account when the provider doesn't exist
|
||||||
// Then: It should be rejected
|
// Then: It should not resolve
|
||||||
ams.addAccount('doesNotExist')
|
Promise.race([
|
||||||
.then(
|
new Promise((resolve, reject) => setTimeout(() => resolve(), 100)),
|
||||||
() => done('Promise resolved when it should have rejected'),
|
ams.addAccount('doesNotExist').then((
|
||||||
() => done()
|
() => done('Promise resolved when the provider did not exist')
|
||||||
);
|
))
|
||||||
|
]).then(() => done(), err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Add account - provider exists, provider fails', done => {
|
test('Add account - provider exists, provider fails', done => {
|
||||||
@@ -305,12 +305,13 @@ suite('Account Management Service Tests:', () => {
|
|||||||
let ams = getTestState().accountManagementService;
|
let ams = getTestState().accountManagementService;
|
||||||
|
|
||||||
// If: I get accounts when the provider doesn't exist
|
// If: I get accounts when the provider doesn't exist
|
||||||
// Then: It should be rejected
|
// Then: It should not resolve
|
||||||
ams.getAccountsForProvider('doesNotExist')
|
Promise.race([
|
||||||
.then(
|
new Promise((resolve, reject) => setTimeout(() => resolve(), 100)),
|
||||||
() => done('Promise resolved when it should have rejected'),
|
ams.getAccountsForProvider('doesNotExist').then((
|
||||||
() => done()
|
() => done('Promise resolved when the provider did not exist')
|
||||||
);
|
))
|
||||||
|
]).then(() => done(), err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Get accounts by provider - provider exists, no accounts', done => {
|
test('Get accounts by provider - provider exists, no accounts', done => {
|
||||||
|
|||||||
Reference in New Issue
Block a user