Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/main.js

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions src/AzureSqlResourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { IAuthorizer } from 'azure-actions-webclient/Authorizer/IAuthorizer';
import { WebRequest } from 'azure-actions-webclient/WebClient';
import { ServiceClient as AzureRestClient, ToError, AzureError } from 'azure-actions-webclient/AzureRestClient'

// API docs: https://docs.microsoft.com/rest/api/sql
const SqlApiVersion = '2021-11-01';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we have a convention for constants in this repo? e.g. SQL_API_VERSION?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No convention I'm aware of, although we should probably have a conversation about that in the future as we implement more features!


export interface AzureSqlServer {
id: string;
kind: string;
Expand Down Expand Up @@ -51,9 +54,10 @@ export default class AzureSqlResourceManager {
let today = new Date();
let firewallRuleName = `ClientIPAddress_${today.getFullYear()}-${today.getMonth()}-${today.getDay()}_${startIpAddress}`;

// https://docs.microsoft.com/rest/api/sql/2021-11-01/firewall-rules/create-or-update
let httpRequest: WebRequest = {
method: 'PUT',
uri: this._restClient.getRequestUri(`/${this._resource!.id}/firewallRules/${firewallRuleName}`, {}, [], '2014-04-01'),
uri: this._restClient.getRequestUri(`/${this._resource!.id}/firewallRules/${firewallRuleName}`, {}, [], SqlApiVersion),
body: JSON.stringify({
'properties': {
'startIpAddress': startIpAddress,
Expand Down Expand Up @@ -81,9 +85,10 @@ export default class AzureSqlResourceManager {
}

public async removeFirewallRule(firewallRule: FirewallRule): Promise<void> {
// https://docs.microsoft.com/rest/api/sql/2021-11-01/firewall-rules/delete
let httpRequest: WebRequest = {
method: 'DELETE',
uri: this._restClient.getRequestUri(`/${this._resource!.id}/firewallRules/${firewallRule.name}`, {}, [], '2014-04-01')
uri: this._restClient.getRequestUri(`/${this._resource!.id}/firewallRules/${firewallRule.name}`, {}, [], SqlApiVersion)
};

try {
Expand All @@ -109,9 +114,10 @@ export default class AzureSqlResourceManager {
serverName = serverName.slice(0, serverName.lastIndexOf(sqlServerHostNameSuffix));
}

// https://docs.microsoft.com/rest/api/sql/2021-11-01/servers/list
let httpRequest: WebRequest = {
method: 'GET',
uri: this._restClient.getRequestUri('//subscriptions/{subscriptionId}/providers/Microsoft.Sql/servers', {}, [], '2015-05-01-preview')
uri: this._restClient.getRequestUri('//subscriptions/{subscriptionId}/providers/Microsoft.Sql/servers', {}, [], SqlApiVersion)
}

try {
Expand Down