Skip to content

Commit 59401b7

Browse files
authored
Merge pull request #31 from alanenriqueo/releases/v1
Release v1.1.0
2 parents 07141f9 + 262f77b commit 59401b7

File tree

1,325 files changed

+53061
-44637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,325 files changed

+53061
-44637
lines changed

lib/Constants.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.PsqlConstants = exports.FirewallConstants = exports.FileConstants = void 0;
3+
exports.PsqlConstants = exports.FileConstants = void 0;
44
class FileConstants {
55
}
66
exports.FileConstants = FileConstants;
77
// regex checks that string should end with .sql and if folderPath is present, * should not be included in folderPath
88
FileConstants.singleParentDirRegex = /^((?!\*\/).)*(\.sql)$/g;
9-
class FirewallConstants {
10-
}
11-
exports.FirewallConstants = FirewallConstants;
12-
FirewallConstants.ipv4MatchPattern = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
139
class PsqlConstants {
1410
}
1511
exports.PsqlConstants = PsqlConstants;

lib/Utils/FirewallUtils/ResourceManager.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,27 @@ class AzurePSQLResourceManager {
4646
getPSQLServer() {
4747
return this._resource;
4848
}
49-
_populatePSQLServerData(serverName) {
49+
_getPSQLServer(serverType, apiVersion, serverName) {
5050
return __awaiter(this, void 0, void 0, function* () {
51-
// trim the cloud hostname suffix from servername
52-
serverName = serverName.split('.')[0];
5351
const httpRequest = {
5452
method: 'GET',
55-
uri: this._restClient.getRequestUri('//subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/servers', {}, [], '2017-12-01')
53+
uri: this._restClient.getRequestUri(`//subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/${serverType}`, {}, [], apiVersion)
5654
};
57-
core.debug(`Get PSQL server '${serverName}' details`);
55+
core.debug(`Get '${serverName}' for PSQL ${serverType} details`);
5856
try {
5957
const httpResponse = yield this._restClient.beginRequest(httpRequest);
6058
if (httpResponse.statusCode !== 200) {
6159
throw AzureRestClient_1.ToError(httpResponse);
6260
}
63-
const sqlServers = httpResponse.body && httpResponse.body.value;
64-
if (sqlServers && sqlServers.length > 0) {
65-
this._resource = sqlServers.filter((sqlResource) => sqlResource.name.toLowerCase() === serverName.toLowerCase())[0];
66-
if (!this._resource) {
67-
throw new Error(`Unable to get details of PSQL server ${serverName}. PSQL server '${serverName}' was not found in the subscription.`);
68-
}
69-
core.debug(JSON.stringify(this._resource));
70-
}
71-
else {
72-
throw new Error(`Unable to get details of PSQL server ${serverName}. No PSQL servers were found in the subscription.`);
61+
const sqlServers = ((httpResponse.body && httpResponse.body.value) || []);
62+
const sqlServer = sqlServers.find((sqlResource) => sqlResource.name.toLowerCase() === serverName.toLowerCase());
63+
if (sqlServer) {
64+
this._serverType = serverType;
65+
this._apiVersion = apiVersion;
66+
this._resource = sqlServer;
67+
return true;
7368
}
69+
return false;
7470
}
7571
catch (error) {
7672
if (error instanceof AzureRestClient_1.AzureError) {
@@ -80,12 +76,22 @@ class AzurePSQLResourceManager {
8076
}
8177
});
8278
}
79+
_populatePSQLServerData(serverName) {
80+
return __awaiter(this, void 0, void 0, function* () {
81+
// trim the cloud hostname suffix from servername
82+
serverName = serverName.split('.')[0];
83+
(yield this._getPSQLServer('servers', '2017-12-01', serverName)) || (yield this._getPSQLServer('flexibleServers', '2021-06-01', serverName));
84+
if (!this._resource) {
85+
throw new Error(`Unable to get details of PSQL server ${serverName}. PSQL server '${serverName}' was not found in the subscription.`);
86+
}
87+
});
88+
}
8389
addFirewallRule(startIpAddress, endIpAddress) {
8490
return __awaiter(this, void 0, void 0, function* () {
8591
const firewallRuleName = `ClientIPAddress_${Date.now()}`;
8692
const httpRequest = {
8793
method: 'PUT',
88-
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${firewallRuleName}`, {}, [], '2017-12-01'),
94+
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${firewallRuleName}`, {}, [], this._apiVersion),
8995
body: JSON.stringify({
9096
'properties': {
9197
'startIpAddress': startIpAddress,
@@ -122,7 +128,7 @@ class AzurePSQLResourceManager {
122128
return __awaiter(this, void 0, void 0, function* () {
123129
const httpRequest = {
124130
method: 'GET',
125-
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${ruleName}`, {}, [], '2017-12-01')
131+
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${ruleName}`, {}, [], this._apiVersion)
126132
};
127133
try {
128134
const httpResponse = yield this._restClient.beginRequest(httpRequest);
@@ -143,7 +149,7 @@ class AzurePSQLResourceManager {
143149
return __awaiter(this, void 0, void 0, function* () {
144150
const httpRequest = {
145151
method: 'DELETE',
146-
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${firewallRule.name}`, {}, [], '2017-12-01')
152+
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${firewallRule.name}`, {}, [], this._apiVersion)
147153
};
148154
try {
149155
const httpResponse = yield this._restClient.beginRequest(httpRequest);

lib/Utils/PsqlUtils/PsqlUtils.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1313
};
1414
Object.defineProperty(exports, "__esModule", { value: true });
1515
const Constants_1 = require("../../Constants");
16-
const Constants_2 = require("../../Constants");
1716
const PsqlToolRunner_1 = __importDefault(require("./PsqlToolRunner"));
17+
const http_client_1 = require("@actions/http-client");
1818
class PsqlUtils {
1919
static detectIPAddress(connectionString) {
20+
var _a;
2021
return __awaiter(this, void 0, void 0, function* () {
2122
let psqlError = '';
2223
let ipAddress = '';
@@ -31,16 +32,17 @@ class PsqlUtils {
3132
// "SELECT 1" psql command is run to check if psql client is able to connect to DB using the connectionString
3233
try {
3334
yield PsqlToolRunner_1.default.init();
34-
yield PsqlToolRunner_1.default.executePsqlCommand(connectionString, Constants_1.PsqlConstants.SELECT_1, options);
35+
yield PsqlToolRunner_1.default.executePsqlCommand(`${connectionString} connect_timeout=10`, Constants_1.PsqlConstants.SELECT_1, options);
3536
}
36-
catch (err) {
37+
catch (_b) {
3738
if (psqlError) {
38-
const ipAddresses = psqlError.match(Constants_2.FirewallConstants.ipv4MatchPattern);
39-
if (ipAddresses) {
40-
ipAddress = ipAddresses[0];
39+
const http = new http_client_1.HttpClient();
40+
try {
41+
const ipv4 = yield http.getJson('https://api.ipify.org?format=json');
42+
ipAddress = ((_a = ipv4.result) === null || _a === void 0 ? void 0 : _a.ip) || '';
4143
}
42-
else {
43-
throw new Error(`Unable to detect client IP Address: ${psqlError}`);
44+
catch (err) {
45+
throw new Error(`Unable to detect client IP Address: ${err.message}`);
4446
}
4547
}
4648
}

node_modules/.bin/acorn

Lines changed: 0 additions & 15 deletions
This file was deleted.

node_modules/.bin/acorn

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/acorn.cmd

Lines changed: 0 additions & 17 deletions
This file was deleted.

node_modules/.bin/acorn.ps1

Lines changed: 0 additions & 18 deletions
This file was deleted.

node_modules/.bin/atob

Lines changed: 0 additions & 15 deletions
This file was deleted.

node_modules/.bin/atob

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/atob.cmd

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)