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
63 changes: 47 additions & 16 deletions forward_engineering/configs/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,61 +69,92 @@ module.exports = {
timestamp: {
format: 'YYYY-MM-DD hh:mm:ss',
},
interval: {},
interval: {
format: 'PnYnMnDTnHnMnS',
},
boolean: {
mode: 'boolean',
},
int4range: {
capacity: 4,
mode: 'range',
modeType: 'integer',
capacity: 4,
},
int8range: {
capacity: 8,
mode: 'range',
modeType: 'integer',
capacity: 8,
},
numrange: {
capacity: 12,
mode: 'decimal',
mode: 'range',
modeType: 'decimal',
capacity: 12,
},
daterange: {
format: 'YYYY-MM-DD',
mode: 'range',
modeType: 'date',
format: 'YYYY-MM-DD',
},
tsrange: {
format: 'YYYY-MM-DD hh:mm:ss',
mode: 'range',
modeType: 'timestamp',
format: 'YYYY-MM-DD hh:mm:ss',
},
tstzrange: {
format: 'YYYY-MM-DD hh:mm:ss',
mode: 'range',
modeType: 'timestamp',
format: 'YYYY-MM-DD hh:mm:ss.nnnZ',
},

int4multirange: {
capacity: 4,
mode: 'multirange',
modeType: 'integer',
capacity: 4,
},
int8multirange: {
capacity: 12,
mode: 'decimal',
mode: 'multirange',
modeType: 'integer',
capacity: 8,
},
nummultirange: {
capacity: 12,
mode: 'decimal',
mode: 'multirange',
modeType: 'decimal',
capacity: 12,
},
datemultirange: {
format: 'YYYY-MM-DD',
mode: 'multirange',
modeType: 'date',
format: 'YYYY-MM-DD',
},
tsmultirange: {
format: 'YYYY-MM-DD hh:mm:ss',
mode: 'multirange',
modeType: 'timestamp',
format: 'YYYY-MM-DD hh:mm:ss',
},
tstzmultirange: {
format: 'YYYY-MM-DD hh:mm:ss',
mode: 'multirange',
modeType: 'timestamp',
format: 'YYYY-MM-DD hh:mm:ss.nnnZ',
},
geometry: {
format: 'euclidian',
mode: 'geospatial',
},
geography: {
format: 'euclidian',
mode: 'geospatial',
},
box2d: {
format: 'euclidian',
mode: 'geospatial',
},
box3d: {
format: 'euclidian',
mode: 'geospatial',
},
geometry_dump: {
format: 'euclidian',
mode: 'geospatial',
},
point: {
format: 'euclidian',
Expand Down
7 changes: 6 additions & 1 deletion properties_pane/field_level/fieldLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,12 @@ making sure that you maintain a proper JSON format.
"box",
"path",
"polygon",
"circle"
"circle",
"box2d",
"box3d",
"geometry",
"geometry_dump",
"geography"
],
"data": "options",
"valueType": "string"
Expand Down
1 change: 1 addition & 0 deletions reverse_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
logger,
});

postgresService.setDependencies(app);
await postgresService.connect(connectionInfo, postgresLogger);
await postgresService.pingDb();
await postgresService.logVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,28 @@
"inputType": "select",
"options": [
{
"value": "Off",
"label": "Off"
"value": "disable",
"label": "Disable"
},
{
"value": "TRUST_ALL_CERTIFICATES",
"label": "Unvalidated"
"value": "allow",
"label": "Allow"
},
{
"value": "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES",
"label": "Server validation"
"value": "prefer",
"label": "Prefer"
},
{
"value": "TRUST_SERVER_CLIENT_CERTIFICATES",
"label": "Server and client validation"
"value": "require",
"label": "Require"
},
{
"value": "verify-ca",
"label": "Verify CA"
},
{
"value": "verify-full",
"label": "Verify Full"
}
]
},
Expand All @@ -97,8 +105,10 @@
"dependency": {
"key": "sslType",
"value": [
"TRUST_CUSTOM_CA_SIGNED_CERTIFICATES",
"TRUST_SERVER_CLIENT_CERTIFICATES"
"prefer",
"require",
"verify-ca",
"verify-full"
]
}
},
Expand All @@ -114,7 +124,12 @@
],
"dependency": {
"key": "sslType",
"value": "TRUST_SERVER_CLIENT_CERTIFICATES"
"value": [
"prefer",
"require",
"verify-ca",
"verify-full"
]
}
},
{
Expand All @@ -129,7 +144,12 @@
],
"dependency": {
"key": "sslType",
"value": "TRUST_SERVER_CLIENT_CERTIFICATES"
"value": [
"prefer",
"require",
"verify-ca",
"verify-full"
]
}
}
]
Expand Down
49 changes: 30 additions & 19 deletions reverse_engineering/helpers/connectionHelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Pool = require('pg').Pool;
const fs = require('fs');
const ssh = require('tunnel-ssh');
const pg = require('pg');

const getSshConfig = info => {
const config = {
Expand Down Expand Up @@ -43,32 +43,41 @@ const connectViaSsh = info =>
});

const getSslOptions = connectionInfo => {
if (connectionInfo.sslType === 'Off') {
const sslType = mapSslType(connectionInfo.sslType);

if (sslType === 'disable') {
return false;
}

if (connectionInfo.sslType === 'Unvalidated') {
return {
rejectUnauthorized: false,
};
if (sslType === 'allow') {
true;
}

if (connectionInfo.sslType === 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES') {
if (['prefer', 'require', 'verify-ca', 'verify-full'].includes(sslType)) {
return {
ca: fs.readFileSync(connectionInfo.certAuthority),
ca: fs.existsSync(connectionInfo.certAuthority)
? fs.readFileSync(connectionInfo.certAuthority).toString()
: '',
cert: fs.existsSync(connectionInfo.clientCert) ? fs.readFileSync(connectionInfo.clientCert).toString() : '',
key: fs.existsSync(connectionInfo.clientPrivateKey)
? fs.readFileSync(connectionInfo.clientPrivateKey).toString()
: '',
};
}
};

if (connectionInfo.sslType === 'TRUST_SERVER_CLIENT_CERTIFICATES') {
return {
ca: fs.readFileSync(connectionInfo.certAuthority),
cert: fs.readFileSync(connectionInfo.clientCert),
key: fs.readFileSync(connectionInfo.clientPrivateKey),
};
}
const mapSslType = sslType => {
const oldToNewSslType = {
Off: 'disable',
TRUST_ALL_CERTIFICATES: 'allow',
TRUST_CUSTOM_CA_SIGNED_CERTIFICATES: 'prefer',
TRUST_SERVER_CLIENT_CERTIFICATES: 'verify-full',
};

return oldToNewSslType[sslType] || sslType;
};

const createConnectionPool = async connectionInfo => {
const createClient = async connectionInfo => {
let sshTunnel = null;

if (connectionInfo.ssh) {
Expand All @@ -88,13 +97,15 @@ const createConnectionPool = async connectionInfo => {
query_timeout: Number(connectionInfo.queryRequestTimeout) || 60000,
statement_timeout: Number(connectionInfo.queryRequestTimeout) || 60000,
database: connectionInfo.database || connectionInfo.maintenanceDatabase,
application_name: 'Hackolade',
};

const pool = await new Pool(config);
const client = new pg.Client(config);
await client.connect();

return { pool, sshTunnel };
return { client, sshTunnel };
};

module.exports = {
createConnectionPool,
createClient,
};
28 changes: 17 additions & 11 deletions reverse_engineering/helpers/db.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
const queryConstants = require('./queryConstants');

let pool = null;
let client = null;
let logger = null;

module.exports = {
initializePool(newPool, newLogger) {
pool = newPool;
initializeClient(newClient, newLogger) {
client = newClient;
logger = newLogger;

pool.on('error', error => newLogger.error(error));
client.on('error', error => newLogger.error(error));
},

isPoolInitialized() {
return Boolean(pool);
isClientInitialized() {
return Boolean(client);
},

async releasePool() {
if (pool) {
await pool.end();
pool = null;
releaseClient() {
if (client) {
return new Promise(resolve => {
client.end(() => {
client = null;
resolve();
});
});
}

return Promise.resolve();
},

async query(query, params, firstRow = false) {
Expand All @@ -28,7 +34,7 @@ module.exports = {
logger.info('Execute query', { queryName, params });

const start = Date.now();
const result = await pool.query(query, params);
const result = await client.query(query, params);
const duration = Date.now() - start;

logger.info('Query executed', { queryName, params, duration, rowsCount: result.rowCount });
Expand Down
5 changes: 5 additions & 0 deletions reverse_engineering/helpers/postgresHelpers/columnHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ const mapType = (userDefinedTypes, type) => {
case 'path':
case 'polygon':
case 'circle':
case 'box2d':
case 'box3d':
case 'geometry':
case 'geometry_dump':
case 'geography':
return { type: 'geometry', mode: type };
case 'bytea':
return { type: 'binary', mode: type };
Expand Down
10 changes: 5 additions & 5 deletions reverse_engineering/helpers/postgresService.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { createConnectionPool } = require('./connectionHelper');
const { createClient } = require('./connectionHelper');
const db = require('./db');
const { getJsonSchema } = require('./getJsonSchema');
const {
Expand Down Expand Up @@ -62,13 +62,13 @@ module.exports = {
},

async connect(connectionInfo, specificLogger) {
if (db.isPoolInitialized()) {
if (db.isClientInitialized()) {
await this.disconnect();
}

const { pool, sshTunnel } = await createConnectionPool(connectionInfo);
const { client, sshTunnel } = await createClient(connectionInfo);

db.initializePool(pool, specificLogger);
db.initializeClient(client, specificLogger);
currentSshTunnel = sshTunnel;
logger = specificLogger;
},
Expand All @@ -79,7 +79,7 @@ module.exports = {
currentSshTunnel = null;
}

await db.releasePool();
await db.releaseClient();
},

pingDb() {
Expand Down
Loading