mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
158
src/sql/parts/accountManagement/common/accountActions.ts
Normal file
158
src/sql/parts/accountManagement/common/accountActions.ts
Normal file
@@ -0,0 +1,158 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as data from 'data';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { localize } from 'vs/nls';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { IMessageService, IConfirmation, Severity } from 'vs/platform/message/common/message';
|
||||
|
||||
import { error } from 'sql/base/common/log';
|
||||
import { IAccountManagementService } from 'sql/services/accountManagement/interfaces';
|
||||
import { IErrorMessageService } from 'sql/parts/connection/common/connectionManagement';
|
||||
|
||||
/**
|
||||
* Actions to add a new account
|
||||
*/
|
||||
export class AddAccountAction extends Action {
|
||||
// CONSTANTS ///////////////////////////////////////////////////////////
|
||||
public static ID = 'account.addLinkedAccount';
|
||||
public static LABEL = localize('addAccount', 'Add an account');
|
||||
|
||||
// EVENTING ////////////////////////////////////////////////////////////
|
||||
private _addAccountCompleteEmitter: Emitter<void>;
|
||||
public get addAccountCompleteEvent(): Event<void> { return this._addAccountCompleteEmitter.event; }
|
||||
|
||||
private _addAccountErrorEmitter: Emitter<string>;
|
||||
public get addAccountErrorEvent(): Event<string> { return this._addAccountErrorEmitter.event; }
|
||||
|
||||
private _addAccountStartEmitter: Emitter<void>;
|
||||
public get addAccountStartEvent(): Event<void> { return this._addAccountStartEmitter.event; }
|
||||
|
||||
constructor(
|
||||
private _providerId: string,
|
||||
@IMessageService private _messageService: IMessageService,
|
||||
@IErrorMessageService private _errorMessageService: IErrorMessageService,
|
||||
@IAccountManagementService private _accountManagementService: IAccountManagementService
|
||||
) {
|
||||
super(AddAccountAction.ID, AddAccountAction.LABEL);
|
||||
this.class = 'add-linked-account-action';
|
||||
|
||||
this._addAccountCompleteEmitter = new Emitter<void>();
|
||||
this._addAccountErrorEmitter = new Emitter<string>();
|
||||
this._addAccountStartEmitter = new Emitter<void>();
|
||||
}
|
||||
|
||||
public run(): TPromise<boolean> {
|
||||
let self = this;
|
||||
|
||||
// Fire the event that we've started adding accounts
|
||||
this._addAccountStartEmitter.fire();
|
||||
|
||||
return new TPromise((resolve, reject) => {
|
||||
self._accountManagementService.addAccount(self._providerId)
|
||||
.then(
|
||||
() => {
|
||||
self._addAccountCompleteEmitter.fire();
|
||||
resolve(true);
|
||||
},
|
||||
err => {
|
||||
error(`Error while adding account: ${err}`);
|
||||
self._addAccountErrorEmitter.fire(err);
|
||||
self._addAccountCompleteEmitter.fire();
|
||||
reject(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions to remove the account
|
||||
*/
|
||||
export class RemoveAccountAction extends Action {
|
||||
public static ID = 'account.removeAccount';
|
||||
public static LABEL = localize('removeAccount', 'Remove account');
|
||||
|
||||
constructor(
|
||||
private _account: data.Account,
|
||||
@IMessageService private _messageService: IMessageService,
|
||||
@IErrorMessageService private _errorMessageService: IErrorMessageService,
|
||||
@IAccountManagementService private _accountManagementService: IAccountManagementService
|
||||
) {
|
||||
super(RemoveAccountAction.ID, RemoveAccountAction.LABEL, 'remove-account-action icon remove');
|
||||
}
|
||||
|
||||
public run(): TPromise<boolean> {
|
||||
let self = this;
|
||||
|
||||
// Ask for Confirm
|
||||
let confirm: IConfirmation = {
|
||||
message: localize('confirmRemoveUserAccountMessage', "Are you sure you want to remove '{0}'?", this._account.displayInfo.displayName),
|
||||
primaryButton: localize('yes', 'Yes'),
|
||||
secondaryButton: localize('no', 'No'),
|
||||
type: 'question'
|
||||
};
|
||||
|
||||
if (!this._messageService.confirm(confirm)) {
|
||||
return TPromise.as(false);
|
||||
}
|
||||
|
||||
return new TPromise((resolve, reject) => {
|
||||
self._accountManagementService.removeAccount(self._account.key)
|
||||
.then(
|
||||
(result) => { resolve(result); },
|
||||
(err) => {
|
||||
// Must handle here as this is an independent action
|
||||
self._errorMessageService.showDialog(Severity.Error,
|
||||
localize('removeAccountFailed', 'Failed to remove account'), err);
|
||||
resolve(false);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions to apply filter to the account
|
||||
*/
|
||||
export class ApplyFilterAction extends Action {
|
||||
public static ID = 'account.applyFilters';
|
||||
public static LABEL = localize('applyFilters', 'Apply Filters');
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string
|
||||
) {
|
||||
super(id, label, 'apply-filters-action icon filter');
|
||||
}
|
||||
|
||||
public run(): TPromise<boolean> {
|
||||
// Todo: apply filter to the account
|
||||
return TPromise.as(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions to refresh the account
|
||||
*/
|
||||
export class RefreshAccountAction extends Action {
|
||||
public static ID = 'account.refresh';
|
||||
public static LABEL = localize('refreshAccount', 'Reenter your credentials');
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string
|
||||
) {
|
||||
super(id, label, 'refresh-account-action icon refresh');
|
||||
}
|
||||
public run(): TPromise<boolean> {
|
||||
// Todo: refresh the account
|
||||
return TPromise.as(true);
|
||||
}
|
||||
}
|
||||
125
src/sql/parts/accountManagement/common/accountListRenderer.ts
Normal file
125
src/sql/parts/accountManagement/common/accountListRenderer.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
import 'vs/css!sql/parts/accountManagement/common/media/accountListRenderer';
|
||||
import 'vs/css!sql/parts/accountManagement/common/media/accountActions';
|
||||
import 'vs/css!sql/media/icons/common-icons';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import { IDelegate, IRenderer } from 'vs/base/browser/ui/list/list';
|
||||
import { ActionBar, IActionOptions } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
import { RemoveAccountAction, ApplyFilterAction, RefreshAccountAction } from 'sql/parts/accountManagement/common/accountActions';
|
||||
|
||||
import * as data from 'data';
|
||||
|
||||
export class AccountListDelegate implements IDelegate<data.Account> {
|
||||
|
||||
constructor(
|
||||
private _height: number
|
||||
) {
|
||||
}
|
||||
|
||||
public getHeight(element: data.Account): number {
|
||||
return this._height;
|
||||
}
|
||||
|
||||
public getTemplateId(element: data.Account): string {
|
||||
return 'accountListRenderer';
|
||||
}
|
||||
}
|
||||
|
||||
export interface AccountListTemplate {
|
||||
root: HTMLElement;
|
||||
icon: HTMLElement;
|
||||
badgeContent: HTMLElement;
|
||||
contextualDisplayName: HTMLElement;
|
||||
label: HTMLElement;
|
||||
displayName: HTMLElement;
|
||||
content?: HTMLElement;
|
||||
actions?: ActionBar;
|
||||
}
|
||||
|
||||
export class AccountPickerListRenderer implements IRenderer<data.Account, AccountListTemplate> {
|
||||
public static TEMPLATE_ID = 'accountListRenderer';
|
||||
|
||||
public get templateId(): string {
|
||||
return AccountPickerListRenderer.TEMPLATE_ID;
|
||||
}
|
||||
|
||||
public renderTemplate(container: HTMLElement): AccountListTemplate {
|
||||
const tableTemplate: AccountListTemplate = Object.create(null);
|
||||
const badge = DOM.$('div.badge');
|
||||
tableTemplate.root = DOM.append(container, DOM.$('div.list-row.account-picker-list'));
|
||||
tableTemplate.icon = DOM.append(tableTemplate.root, DOM.$('div.icon'));
|
||||
DOM.append(tableTemplate.icon, badge);
|
||||
tableTemplate.badgeContent = DOM.append(badge, DOM.$('div.badge-content'));
|
||||
tableTemplate.label = DOM.append(tableTemplate.root, DOM.$('div.label'));
|
||||
tableTemplate.contextualDisplayName = DOM.append(tableTemplate.label, DOM.$('div.contextual-display-name'));
|
||||
tableTemplate.displayName = DOM.append(tableTemplate.label, DOM.$('div.display-name'));
|
||||
return tableTemplate;
|
||||
}
|
||||
|
||||
public renderElement(account: data.Account, index: number, templateData: AccountListTemplate): void {
|
||||
// Set the account icon
|
||||
templateData.icon.classList.add('account-logo');
|
||||
templateData.icon.style.background = `url('data:${account.displayInfo.contextualLogo.light}')`;
|
||||
// TODO: Pick between the light and dark logo
|
||||
|
||||
templateData.contextualDisplayName.innerText = account.displayInfo.contextualDisplayName;
|
||||
templateData.displayName.innerText = account.displayInfo.displayName;
|
||||
if (account.isStale) {
|
||||
templateData.badgeContent.className = 'badge-content icon warning-badge';
|
||||
} else {
|
||||
templateData.badgeContent.className = 'badge-content';
|
||||
}
|
||||
}
|
||||
|
||||
public disposeTemplate(template: AccountListTemplate): void {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
export class AccountListRenderer extends AccountPickerListRenderer {
|
||||
constructor(
|
||||
@IInstantiationService private _instantiationService: IInstantiationService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public get templateId(): string {
|
||||
return AccountListRenderer.TEMPLATE_ID;
|
||||
}
|
||||
|
||||
public renderTemplate(container: HTMLElement): AccountListTemplate {
|
||||
const tableTemplate = super.renderTemplate(container);
|
||||
tableTemplate.content = DOM.append(tableTemplate.label, DOM.$('div.content'));
|
||||
tableTemplate.actions = new ActionBar(tableTemplate.root, { animated: false });
|
||||
|
||||
return tableTemplate;
|
||||
}
|
||||
|
||||
public renderElement(account: data.Account, index: number, templateData: AccountListTemplate): void {
|
||||
super.renderElement(account, index, templateData);
|
||||
if (account.isStale) {
|
||||
templateData.content.innerText = localize('refreshCredentials', 'You need to refresh the credentials for this account.');
|
||||
} else {
|
||||
templateData.content.innerText = '';
|
||||
}
|
||||
templateData.actions.clear();
|
||||
|
||||
let actionOptions: IActionOptions = { icon: true, label: false };
|
||||
if (account.isStale) {
|
||||
templateData.actions.push(new RefreshAccountAction(RefreshAccountAction.ID, RefreshAccountAction.LABEL), actionOptions);
|
||||
} else {
|
||||
templateData.actions.push(new ApplyFilterAction(ApplyFilterAction.ID, ApplyFilterAction.LABEL), actionOptions);
|
||||
}
|
||||
|
||||
let removeAction = this._instantiationService.createInstance(RemoveAccountAction, account);
|
||||
templateData.actions.push(removeAction, actionOptions);
|
||||
}
|
||||
}
|
||||
61
src/sql/parts/accountManagement/common/interfaces.ts
Normal file
61
src/sql/parts/accountManagement/common/interfaces.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import Event from 'vs/base/common/event';
|
||||
import * as data from 'data';
|
||||
|
||||
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
||||
|
||||
export const SERVICE_ID = 'resourceProviderService';
|
||||
export const IResourceProviderService = createDecorator<IResourceProviderService>(SERVICE_ID);
|
||||
|
||||
export interface IHandleFirewallRuleResult {
|
||||
canHandleFirewallRule: boolean;
|
||||
ipAddress: string;
|
||||
resourceProviderId: string;
|
||||
}
|
||||
|
||||
export interface IResourceProviderService {
|
||||
_serviceBrand: any;
|
||||
|
||||
/**
|
||||
* Register a resource provider
|
||||
*/
|
||||
registerProvider(providerId: string, provider: data.ResourceProvider): void;
|
||||
|
||||
/**
|
||||
* Unregister a resource provider
|
||||
*/
|
||||
unregisterProvider(ProviderId: string): void;
|
||||
|
||||
/**
|
||||
* Create a firewall rule
|
||||
*/
|
||||
createFirewallRule(selectedAccount: data.Account, firewallruleInfo: data.FirewallRuleInfo, resourceProviderId: string): Promise<data.CreateFirewallRuleResponse>;
|
||||
|
||||
/**
|
||||
* handle a firewall rule
|
||||
*/
|
||||
handleFirewallRule(errorCode: number, errorMessage: string, connectionTypeId: string): Promise<IHandleFirewallRuleResult>;
|
||||
|
||||
/**
|
||||
* Show firewall rule dialog
|
||||
*/
|
||||
showFirewallRuleDialog(connection: IConnectionProfile, ipAddress: string, resourceProviderId: string): Promise<boolean>;
|
||||
}
|
||||
|
||||
export const IAccountPickerService = createDecorator<IAccountPickerService>('AccountPickerService');
|
||||
export interface IAccountPickerService {
|
||||
_serviceBrand: any;
|
||||
renderAccountPicker(container: HTMLElement): void;
|
||||
addAccountCompleteEvent: Event<void>;
|
||||
addAccountErrorEvent: Event<string>;
|
||||
addAccountStartEvent: Event<void>;
|
||||
onAccountSelectionChangeEvent: Event<data.Account>;
|
||||
selectedAccount: data.Account;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/* Icons for various account actions */
|
||||
.vs .action-item .icon.add-linked-account-action {
|
||||
background-image: url('new_account.svg');
|
||||
}
|
||||
|
||||
.vs-dark .action-item .icon.add-linked-account-action,
|
||||
.hc-black .action-item .icon.add-linked-account-action {
|
||||
background-image: url('new_account_inverse.svg');
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
.list-row.account-picker-list {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.list-row.account-picker-list .label {
|
||||
flex: 1 1 auto;
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
.list-row.account-picker-list .label .contextual-display-name {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.list-row.account-picker-list .label .content {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.account-logo {
|
||||
background: no-repeat center center;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><title>new_account_16x16</title><path d="M8.09,7.39a5.91,5.91,0,0,1,1.38.74,6.06,6.06,0,0,1,1.13,1.06A6,6,0,0,1,11.88,12h-1a4.94,4.94,0,0,0-.63-1.61A5,5,0,0,0,7.66,8.3a5,5,0,0,0-3-.12,5.09,5.09,0,0,0-1.2.5,5,5,0,0,0-1.79,1.79,5.07,5.07,0,0,0-.5,1.2A4.88,4.88,0,0,0,1,13H0a5.88,5.88,0,0,1,.28-1.8A6,6,0,0,1,1,9.59a6.1,6.1,0,0,1,1.22-1.3,5.8,5.8,0,0,1,1.59-.9A4.2,4.2,0,0,1,2.46,5.94,3.86,3.86,0,0,1,2,4a3.92,3.92,0,0,1,.31-1.56A4,4,0,0,1,4.4.31a4,4,0,0,1,3.12,0A4,4,0,0,1,9.65,2.44,4,4,0,0,1,9.83,5a4,4,0,0,1-1,1.74A3.94,3.94,0,0,1,8.09,7.39ZM3,4A2.92,2.92,0,0,0,3.2,5.17a3,3,0,0,0,1.6,1.6,3,3,0,0,0,2.33,0,3,3,0,0,0,1.6-1.6,3,3,0,0,0,0-2.33,3,3,0,0,0-1.6-1.6,3,3,0,0,0-2.33,0,3,3,0,0,0-1.6,1.6A2.92,2.92,0,0,0,3,4Zm13,9v1H14v2H13V14H11V13h2V11h1v2Z"/></svg>
|
||||
|
After Width: | Height: | Size: 850 B |
@@ -0,0 +1 @@
|
||||
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><defs><style>.cls-1{fill:#fff;}</style></defs><title>new_account_inverse_16x16</title><path class="cls-1" d="M8.13,7.39a5.91,5.91,0,0,1,1.38.74,6.06,6.06,0,0,1,1.13,1.06A6,6,0,0,1,11.91,12h-1a4.94,4.94,0,0,0-.63-1.61A5,5,0,0,0,7.7,8.3a5,5,0,0,0-3-.12,5.09,5.09,0,0,0-1.2.5,5,5,0,0,0-1.79,1.79,5.07,5.07,0,0,0-.5,1.2A4.88,4.88,0,0,0,1,13H0a5.88,5.88,0,0,1,.28-1.8,6,6,0,0,1,.79-1.6,6.1,6.1,0,0,1,1.22-1.3,5.8,5.8,0,0,1,1.59-.9A4.2,4.2,0,0,1,2.5,5.94,3.86,3.86,0,0,1,2,4a3.92,3.92,0,0,1,.31-1.56A4,4,0,0,1,4.44.31a4,4,0,0,1,3.12,0A4,4,0,0,1,9.69,2.44,4,4,0,0,1,9.87,5a4,4,0,0,1-1,1.74A3.94,3.94,0,0,1,8.13,7.39ZM3,4a2.92,2.92,0,0,0,.23,1.17,3,3,0,0,0,1.6,1.6,3,3,0,0,0,2.33,0,3,3,0,0,0,1.6-1.6,3,3,0,0,0,0-2.33,3,3,0,0,0-1.6-1.6,3,3,0,0,0-2.33,0,3,3,0,0,0-1.6,1.6A2.92,2.92,0,0,0,3,4Zm13,9v1H14v2H13V14H11V13h2V11h1v2Z"/></svg>
|
||||
|
After Width: | Height: | Size: 918 B |
@@ -0,0 +1,114 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
|
||||
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
||||
import { IResourceProviderService, IHandleFirewallRuleResult } from 'sql/parts/accountManagement/common/interfaces';
|
||||
import * as Constants from 'sql/common/constants';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import * as TelemetryUtils from 'sql/common/telemetryUtilities';
|
||||
import { FirewallRuleDialogController } from 'sql/parts/accountManagement/firewallRuleDialog/firewallRuleDialogController';
|
||||
|
||||
import * as data from 'data';
|
||||
|
||||
export class ResourceProviderService implements IResourceProviderService {
|
||||
|
||||
public _serviceBrand: any;
|
||||
private _providers: { [handle: string]: data.ResourceProvider; } = Object.create(null);
|
||||
private _firewallRuleDialogController: FirewallRuleDialogController;
|
||||
|
||||
constructor(
|
||||
@ITelemetryService private _telemetryService: ITelemetryService,
|
||||
@IInstantiationService private _instantiationService: IInstantiationService,
|
||||
@IEnvironmentService private _environmentService: IEnvironmentService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the firewall rule dialog
|
||||
*/
|
||||
public showFirewallRuleDialog(connection: IConnectionProfile, ipAddress: string, resourceProviderId: string): Promise<boolean> {
|
||||
let self = this;
|
||||
// If the firewall rule dialog hasn't been defined, create a new one
|
||||
if (!self._firewallRuleDialogController) {
|
||||
self._firewallRuleDialogController = self._instantiationService.createInstance(FirewallRuleDialogController);
|
||||
}
|
||||
|
||||
return self._firewallRuleDialogController.openFirewallRuleDialog(connection, ipAddress, resourceProviderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a firewall rule
|
||||
*/
|
||||
public createFirewallRule(selectedAccount: data.Account, firewallruleInfo: data.FirewallRuleInfo, resourceProviderId: string): Promise<data.CreateFirewallRuleResponse> {
|
||||
return new Promise<data.CreateFirewallRuleResponse>((resolve, reject) => {
|
||||
let provider = this._providers[resourceProviderId];
|
||||
if (provider) {
|
||||
TelemetryUtils.addTelemetry(this._telemetryService, TelemetryKeys.FirewallRuleRequested, { provider: resourceProviderId });
|
||||
provider.createFirewallRule(selectedAccount, firewallruleInfo).then(result => {
|
||||
resolve(result);
|
||||
}, error => {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(Constants.InvalidProvider);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a firewall rule
|
||||
*/
|
||||
public handleFirewallRule(errorCode: number, errorMessage: string, connectionTypeId: string): Promise<IHandleFirewallRuleResult> {
|
||||
if (!this._environmentService.isBuilt) {
|
||||
let self = this;
|
||||
return new Promise<IHandleFirewallRuleResult>((resolve, reject) => {
|
||||
let handleFirewallRuleResult: IHandleFirewallRuleResult;
|
||||
let promises = [];
|
||||
if (self._providers) {
|
||||
for (let key in self._providers) {
|
||||
let provider = self._providers[key];
|
||||
promises.push(provider.handleFirewallRule(errorCode, errorMessage, connectionTypeId)
|
||||
.then(response => {
|
||||
if (response.result) {
|
||||
handleFirewallRuleResult = { canHandleFirewallRule: response.result, ipAddress: response.ipAddress, resourceProviderId: key };
|
||||
}
|
||||
},
|
||||
() => { /* Swallow failures at getting accounts, we'll just hide that provider */
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Promise.all(promises).then(() => {
|
||||
if (handleFirewallRuleResult) {
|
||||
resolve(handleFirewallRuleResult);
|
||||
} else {
|
||||
handleFirewallRuleResult = { canHandleFirewallRule: false, ipAddress: undefined, resourceProviderId: undefined };
|
||||
resolve(handleFirewallRuleResult);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return new Promise<IHandleFirewallRuleResult>((resolve, reject) => {
|
||||
resolve({ canHandleFirewallRule: false, ipAddress: undefined, resourceProviderId: undefined });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a resource provider
|
||||
*/
|
||||
public registerProvider(providerId: string, provider: data.ResourceProvider): void {
|
||||
this._providers[providerId] = provider;
|
||||
}
|
||||
|
||||
public unregisterProvider(providerId: string): void {
|
||||
delete this._providers[providerId];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user