Skip to content

Commit

Permalink
Merge pull request #31 from alanenriqueo/releases/v1
Browse files Browse the repository at this point in the history
Release v1.1.0
  • Loading branch information
DaeunYim authored Aug 5, 2022
2 parents 07141f9 + 262f77b commit 59401b7
Show file tree
Hide file tree
Showing 1,325 changed files with 53,061 additions and 44,637 deletions.
6 changes: 1 addition & 5 deletions lib/Constants.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PsqlConstants = exports.FirewallConstants = exports.FileConstants = void 0;
exports.PsqlConstants = exports.FileConstants = void 0;
class FileConstants {
}
exports.FileConstants = FileConstants;
// regex checks that string should end with .sql and if folderPath is present, * should not be included in folderPath
FileConstants.singleParentDirRegex = /^((?!\*\/).)*(\.sql)$/g;
class FirewallConstants {
}
exports.FirewallConstants = FirewallConstants;
FirewallConstants.ipv4MatchPattern = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
class PsqlConstants {
}
exports.PsqlConstants = PsqlConstants;
Expand Down
42 changes: 24 additions & 18 deletions lib/Utils/FirewallUtils/ResourceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,27 @@ class AzurePSQLResourceManager {
getPSQLServer() {
return this._resource;
}
_populatePSQLServerData(serverName) {
_getPSQLServer(serverType, apiVersion, serverName) {
return __awaiter(this, void 0, void 0, function* () {
// trim the cloud hostname suffix from servername
serverName = serverName.split('.')[0];
const httpRequest = {
method: 'GET',
uri: this._restClient.getRequestUri('//subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/servers', {}, [], '2017-12-01')
uri: this._restClient.getRequestUri(`//subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/${serverType}`, {}, [], apiVersion)
};
core.debug(`Get PSQL server '${serverName}' details`);
core.debug(`Get '${serverName}' for PSQL ${serverType} details`);
try {
const httpResponse = yield this._restClient.beginRequest(httpRequest);
if (httpResponse.statusCode !== 200) {
throw AzureRestClient_1.ToError(httpResponse);
}
const sqlServers = httpResponse.body && httpResponse.body.value;
if (sqlServers && sqlServers.length > 0) {
this._resource = sqlServers.filter((sqlResource) => sqlResource.name.toLowerCase() === serverName.toLowerCase())[0];
if (!this._resource) {
throw new Error(`Unable to get details of PSQL server ${serverName}. PSQL server '${serverName}' was not found in the subscription.`);
}
core.debug(JSON.stringify(this._resource));
}
else {
throw new Error(`Unable to get details of PSQL server ${serverName}. No PSQL servers were found in the subscription.`);
const sqlServers = ((httpResponse.body && httpResponse.body.value) || []);
const sqlServer = sqlServers.find((sqlResource) => sqlResource.name.toLowerCase() === serverName.toLowerCase());
if (sqlServer) {
this._serverType = serverType;
this._apiVersion = apiVersion;
this._resource = sqlServer;
return true;
}
return false;
}
catch (error) {
if (error instanceof AzureRestClient_1.AzureError) {
Expand All @@ -80,12 +76,22 @@ class AzurePSQLResourceManager {
}
});
}
_populatePSQLServerData(serverName) {
return __awaiter(this, void 0, void 0, function* () {
// trim the cloud hostname suffix from servername
serverName = serverName.split('.')[0];
(yield this._getPSQLServer('servers', '2017-12-01', serverName)) || (yield this._getPSQLServer('flexibleServers', '2021-06-01', serverName));
if (!this._resource) {
throw new Error(`Unable to get details of PSQL server ${serverName}. PSQL server '${serverName}' was not found in the subscription.`);
}
});
}
addFirewallRule(startIpAddress, endIpAddress) {
return __awaiter(this, void 0, void 0, function* () {
const firewallRuleName = `ClientIPAddress_${Date.now()}`;
const httpRequest = {
method: 'PUT',
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${firewallRuleName}`, {}, [], '2017-12-01'),
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${firewallRuleName}`, {}, [], this._apiVersion),
body: JSON.stringify({
'properties': {
'startIpAddress': startIpAddress,
Expand Down Expand Up @@ -122,7 +128,7 @@ class AzurePSQLResourceManager {
return __awaiter(this, void 0, void 0, function* () {
const httpRequest = {
method: 'GET',
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${ruleName}`, {}, [], '2017-12-01')
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${ruleName}`, {}, [], this._apiVersion)
};
try {
const httpResponse = yield this._restClient.beginRequest(httpRequest);
Expand All @@ -143,7 +149,7 @@ class AzurePSQLResourceManager {
return __awaiter(this, void 0, void 0, function* () {
const httpRequest = {
method: 'DELETE',
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${firewallRule.name}`, {}, [], '2017-12-01')
uri: this._restClient.getRequestUri(`/${this._resource.id}/firewallRules/${firewallRule.name}`, {}, [], this._apiVersion)
};
try {
const httpResponse = yield this._restClient.beginRequest(httpRequest);
Expand Down
18 changes: 10 additions & 8 deletions lib/Utils/PsqlUtils/PsqlUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const Constants_1 = require("../../Constants");
const Constants_2 = require("../../Constants");
const PsqlToolRunner_1 = __importDefault(require("./PsqlToolRunner"));
const http_client_1 = require("@actions/http-client");
class PsqlUtils {
static detectIPAddress(connectionString) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
let psqlError = '';
let ipAddress = '';
Expand All @@ -31,16 +32,17 @@ class PsqlUtils {
// "SELECT 1" psql command is run to check if psql client is able to connect to DB using the connectionString
try {
yield PsqlToolRunner_1.default.init();
yield PsqlToolRunner_1.default.executePsqlCommand(connectionString, Constants_1.PsqlConstants.SELECT_1, options);
yield PsqlToolRunner_1.default.executePsqlCommand(`${connectionString} connect_timeout=10`, Constants_1.PsqlConstants.SELECT_1, options);
}
catch (err) {
catch (_b) {
if (psqlError) {
const ipAddresses = psqlError.match(Constants_2.FirewallConstants.ipv4MatchPattern);
if (ipAddresses) {
ipAddress = ipAddresses[0];
const http = new http_client_1.HttpClient();
try {
const ipv4 = yield http.getJson('https://api.ipify.org?format=json');
ipAddress = ((_a = ipv4.result) === null || _a === void 0 ? void 0 : _a.ip) || '';
}
else {
throw new Error(`Unable to detect client IP Address: ${psqlError}`);
catch (err) {
throw new Error(`Unable to detect client IP Address: ${err.message}`);
}
}
}
Expand Down
15 changes: 0 additions & 15 deletions node_modules/.bin/acorn

This file was deleted.

1 change: 1 addition & 0 deletions node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions node_modules/.bin/acorn.cmd

This file was deleted.

18 changes: 0 additions & 18 deletions node_modules/.bin/acorn.ps1

This file was deleted.

15 changes: 0 additions & 15 deletions node_modules/.bin/atob

This file was deleted.

1 change: 1 addition & 0 deletions node_modules/.bin/atob

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions node_modules/.bin/atob.cmd

This file was deleted.

18 changes: 0 additions & 18 deletions node_modules/.bin/atob.ps1

This file was deleted.

15 changes: 0 additions & 15 deletions node_modules/.bin/escodegen

This file was deleted.

1 change: 1 addition & 0 deletions node_modules/.bin/escodegen

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions node_modules/.bin/escodegen.cmd

This file was deleted.

18 changes: 0 additions & 18 deletions node_modules/.bin/escodegen.ps1

This file was deleted.

15 changes: 0 additions & 15 deletions node_modules/.bin/esgenerate

This file was deleted.

1 change: 1 addition & 0 deletions node_modules/.bin/esgenerate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions node_modules/.bin/esgenerate.cmd

This file was deleted.

18 changes: 0 additions & 18 deletions node_modules/.bin/esgenerate.ps1

This file was deleted.

15 changes: 0 additions & 15 deletions node_modules/.bin/esparse

This file was deleted.

1 change: 1 addition & 0 deletions node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 59401b7

Please sign in to comment.