Skip to content

Commit

Permalink
Firewall rule dialog creation support (#143)
Browse files Browse the repository at this point in the history
* Revert "Revert "Firewall feature (#119)" (#126)"

This reverts commit c8747de.

* Shortening path length for install directory

* Localizing firewall ui elements
  • Loading branch information
rishky-msft authored Feb 24, 2023
1 parent d508d4a commit fd61ae8
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"vscode.sql"
],
"scripts": {
"localize": "gulp ext:localize",
"compile": "gulp build",
"package": "gulp package:online",
"package-offline": "gulp package:offline"
Expand Down
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Linux": "linux-x64.tar.gz",
"Ubuntu_22": "ubuntu22-x64.tar.gz"
},
"installDirectory": "ossdbtoolsservice/{#platform#}/{#version#}",
"installDirectory": "bin/{#platform#}/{#version#}",
"executableFiles": [
"mysqltoolsservice/ossdbtoolsservice_main",
"mysqltoolsservice/ossdbtoolsservice_main.exe"
Expand Down
73 changes: 70 additions & 3 deletions src/features/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { NotificationType } from "vscode-languageclient";
import * as azdata from 'azdata';
import { NotificationType, RequestType } from "vscode-languageclient";
import * as telemetry from '@microsoft/ads-extension-telemetry';


// ------------------------------- < Telemetry Sent Event > ------------------------------------
// ------------------------------- < Telemetry Feature Events > ------------------------------------

/**
* Event sent when the language service send a telemetry event
Expand All @@ -28,5 +29,71 @@ export class TelemetryParams {
measures: telemetry.TelemetryEventMeasures;
}
}
// ------------------------------- </ Telemetry Sent Event > ------------------------------------
// ------------------------------- </ Telemetry Feature Events > ------------------------------------

// ------------------------------- < Firewall Rule Feature Events > ------------------------------------

/**
* A request to open up a firewall rule
*/
export namespace CreateFirewallRuleRequest {
export const type = new RequestType<CreateFirewallRuleParams, azdata.CreateFirewallRuleResponse, void, void>('resource/createFirewallRule');
}

/**
* Firewall rule request handler
*/
export namespace HandleFirewallRuleRequest {
export const type = new RequestType<HandleFirewallRuleParams, azdata.HandleFirewallRuleResponse, void, void>('resource/handleFirewallRule');
}

/**
* Firewall rule creation parameters
*/
export interface CreateFirewallRuleParams {
/**
* Account information to use in connecting to Azure
*/
account: azdata.Account;
/**
* Fully qualified name of the server to create a new firewall rule on
*/
serverName: string;
/**
* Start of the IP address range
*/
startIpAddress: string;
/**
* End of the IP address range
*/
endIpAddress: string;
/**
* Firewall rule name
*/
firewallRuleName: string;
/**
* Per-tenant token mappings. Ideally would be set independently of this call,
* but for now this allows us to get the tokens necessary to find a server and open a firewall rule
*/
securityTokenMappings: {};
}

/**
* Firewall rule handling parameters
*/
export interface HandleFirewallRuleParams {
/**
* The error code used to defined the error type
*/
errorCode: number;
/**
* The error message from which to parse the IP address
*/
errorMessage: string;
/**
* The connection type, for example MSSQL
*/
connectionTypeId: string;
}

// ------------------------------- </ Firewall Rule Feature Events > ------------------------------------
67 changes: 67 additions & 0 deletions src/features/firewall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import * as azdata from 'azdata';
import { SqlOpsDataClient, SqlOpsFeature } from "dataprotocol-client";
import { ClientCapabilities, Disposable, RPCMessageType, ServerCapabilities } from "vscode-languageclient";
import { CreateFirewallRuleParams, CreateFirewallRuleRequest, HandleFirewallRuleParams, HandleFirewallRuleRequest } from "./contracts";
import * as UUID from 'vscode-languageclient/lib/utils/uuid';
import * as Utils from '../utils';
import { AzureMysqlResourceProviderName } from '../uiConstants';



export class FireWallFeature extends SqlOpsFeature<any> {

private static readonly messagesTypes: RPCMessageType[] = [
CreateFirewallRuleRequest.type,
HandleFirewallRuleRequest.type
];

constructor(client: SqlOpsDataClient) {
super(client, FireWallFeature.messagesTypes);
}

public fillClientCapabilities(capabilities: ClientCapabilities): void {
Utils.ensure(capabilities, 'firewall')!.firewall = true;
}

public initialize(capabilities: ServerCapabilities): void {
this.register(this.messages, {
id: UUID.generateUuid(),
registerOptions: undefined
});
}

protected registerProvider(options: any): Disposable {
const client = this._client;

let createFirewallRule = (account: azdata.Account, firewallruleInfo: azdata.FirewallRuleInfo): Thenable<azdata.CreateFirewallRuleResponse> => {
return client.sendRequest(CreateFirewallRuleRequest.type, asCreateFirewallRuleParams(account, firewallruleInfo));
};

let handleFirewallRule = (errorCode: number, errorMessage: string, connectionTypeId: string): Thenable<azdata.HandleFirewallRuleResponse> => {
let params: HandleFirewallRuleParams = { errorCode: errorCode, errorMessage: errorMessage, connectionTypeId: connectionTypeId };
return client.sendRequest(HandleFirewallRuleRequest.type, params);
};

return azdata.resources.registerResourceProvider({
displayName: AzureMysqlResourceProviderName,
id: 'Microsoft.Azure.MySQL.ResourceProvider',
settings: {

}
}, {
handleFirewallRule,
createFirewallRule
});
}
}

function asCreateFirewallRuleParams(account: azdata.Account, params: azdata.FirewallRuleInfo): CreateFirewallRuleParams {
return {
account: account,
serverName: params.serverName,
startIpAddress: params.startIpAddress,
endIpAddress: params.endIpAddress,
securityTokenMappings: params.securityTokenMappings,
firewallRuleName: params.firewallRuleName
};
}
3 changes: 3 additions & 0 deletions src/l10n/l10n.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,8 @@
<trans-unit id="databaseCollationLabel">
<source xml:lang="en">Collation</source>
</trans-unit>
<trans-unit id="azureMysqlResourceProviderName">
<source xml:lang="en">Azure MySQL Resource Provider</source>
</trans-unit>
</body></file>
</xliff>
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as Utils from './utils';
import { TelemetryReporter, LanguageClientErrorHandler } from './telemetry';
import { TelemetryFeature } from './features/telemetry';
import { registerDbDesignerCommands } from './features/dbDesigner';
import { FireWallFeature } from './features/firewall'

const baseConfig = require('./config.json');
const outputChannel = vscode.window.createOutputChannel(Constants.serviceName);
Expand Down Expand Up @@ -54,8 +55,9 @@ export async function activate(context: vscode.ExtensionContext) {
features: [
// we only want to add new features
...SqlOpsDataClient.defaultFeatures,
TelemetryFeature
]
TelemetryFeature,
FireWallFeature
],
};

const installationStart = Date.now();
Expand Down
3 changes: 2 additions & 1 deletion src/uiConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export const DatabaseNameLabel = localize('databaseNameLabel', 'Name')
export const DatabaseCharsetDropDownLabel = localize('databaseCharsetDropDownLabel', 'Database Charset Dropdown')
export const DatabaseCharsetLabel = localize('databaseCharsetLabel', 'Charset')
export const DatabaseCollationDropDownLabel = localize('databaseCollationDropDownLabel', 'Database Collation Dropdown')
export const DatabaseCollationLabel = localize('databaseCollationLabel', 'Collation')
export const DatabaseCollationLabel = localize('databaseCollationLabel', 'Collation')
export const AzureMysqlResourceProviderName = localize('azureMysqlResourceProviderName', 'Azure MySQL Resource Provider')

0 comments on commit fd61ae8

Please sign in to comment.