Skip to content

Commit f75dc22

Browse files
committed
RE: fixed SSL connection
1 parent c45e07c commit f75dc22

File tree

199 files changed

+19814
-128
lines changed

Some content is hidden

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

199 files changed

+19814
-128
lines changed

reverse_engineering/helpers/connectionHelper.js

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
const fs = require('fs');
22
const ssh = require('tunnel-ssh');
3-
4-
let Client = null;
5-
6-
const setConnectionHelperDependencies = app => {
7-
Client = app.require('pg-native');
8-
};
3+
const pg = require('pg');
94

105
const getSshConfig = info => {
116
const config = {
@@ -51,20 +46,22 @@ const getSslOptions = connectionInfo => {
5146
const sslType = mapSslType(connectionInfo.sslType);
5247

5348
if (sslType === 'disable') {
54-
return {};
49+
return false;
5550
}
5651

5752
if (sslType === 'allow') {
58-
return {
59-
rejectUnauthorized: false,
60-
};
53+
true;
6154
}
6255

6356
if (['prefer', 'require', 'verify-ca', 'verify-full'].includes(sslType)) {
6457
return {
65-
sslrootcert: connectionInfo.certAuthority,
66-
sslcert: connectionInfo.clientCert,
67-
sslkey: connectionInfo.clientPrivateKey,
58+
ca: fs.existsSync(connectionInfo.certAuthority)
59+
? fs.readFileSync(connectionInfo.certAuthority).toString()
60+
: '',
61+
cert: fs.existsSync(connectionInfo.clientCert) ? fs.readFileSync(connectionInfo.clientCert).toString() : '',
62+
key: fs.existsSync(connectionInfo.clientPrivateKey)
63+
? fs.readFileSync(connectionInfo.clientPrivateKey).toString()
64+
: '',
6865
};
6966
}
7067
};
@@ -91,49 +88,24 @@ const createClient = async connectionInfo => {
9188

9289
const config = {
9390
host: connectionInfo.host,
94-
port: connectionInfo.port,
95-
dbname: connectionInfo.database || connectionInfo.maintenanceDatabase,
9691
user: connectionInfo.userName,
9792
password: connectionInfo.userPassword,
98-
connect_timeout: Number(connectionInfo.queryRequestTimeout) || 60000,
99-
application_name: 'hackolade',
100-
keepalives: 1,
101-
sslmode: connectionInfo.sslType,
102-
...getSslOptions(connectionInfo),
93+
port: connectionInfo.port,
94+
keepAlive: true,
95+
ssl: getSslOptions(connectionInfo),
96+
connectionTimeoutMillis: Number(connectionInfo.queryRequestTimeout) || 60000,
97+
query_timeout: Number(connectionInfo.queryRequestTimeout) || 60000,
98+
statement_timeout: Number(connectionInfo.queryRequestTimeout) || 60000,
99+
database: connectionInfo.database || connectionInfo.maintenanceDatabase,
100+
application_name: 'Hackolade',
103101
};
104102

105-
const client = await connectClient(config);
103+
const client = new pg.Client(config);
104+
await client.connect();
106105

107106
return { client, sshTunnel };
108107
};
109108

110-
const connectClient = config => {
111-
return new Promise((resolve, reject) => {
112-
const paramsString = Object.entries(config)
113-
.map(([key, value]) => getParameter(key, value))
114-
.join(' ');
115-
116-
const client = new Client();
117-
118-
client.connect(paramsString, error => {
119-
if (error) {
120-
return reject(error);
121-
}
122-
123-
resolve(client);
124-
});
125-
});
126-
};
127-
128-
const getParameter = (key, value) => {
129-
if (value?.toString()) {
130-
return `${key}=${value}`;
131-
}
132-
133-
return '';
134-
};
135-
136109
module.exports = {
137110
createClient,
138-
setConnectionHelperDependencies,
139111
};

reverse_engineering/helpers/db.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const queryConstants = require('./queryConstants');
22

33
let client = null;
44
let logger = null;
5-
let queue = [];
65

76
module.exports = {
87
initializeClient(newClient, newLogger) {
@@ -35,7 +34,7 @@ module.exports = {
3534
logger.info('Execute query', { queryName, params });
3635

3736
const start = Date.now();
38-
const result = await this._executeQuery(query, params);
37+
const result = await client.query(query, params);
3938
const duration = Date.now() - start;
4039

4140
logger.info('Query executed', { queryName, params, duration, rowsCount: result.rowCount });
@@ -57,16 +56,4 @@ module.exports = {
5756
return null;
5857
}
5958
},
60-
61-
_executeQuery(query, params = []) {
62-
return new Promise((resolve, reject) => {
63-
try {
64-
const rows = client.querySync(query, params);
65-
66-
resolve({ rows });
67-
} catch (err) {
68-
return reject(err);
69-
}
70-
});
71-
},
7259
};

reverse_engineering/helpers/postgresService.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { createClient, setConnectionHelperDependencies } = require('./connectionHelper');
1+
const { createClient } = require('./connectionHelper');
22
const db = require('./db');
33
const { getJsonSchema } = require('./getJsonSchema');
44
const {
@@ -52,7 +52,6 @@ let logger = null;
5252
module.exports = {
5353
setDependencies(app) {
5454
_ = app.require('lodash');
55-
setConnectionHelperDependencies(app);
5655
setDependenciesInCommonHelper(app);
5756
setDependenciesInTableHelper(app);
5857
setDependenciesInColumnHelper(app);

reverse_engineering/node_modules/buffer-writer/.travis.yml

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

reverse_engineering/node_modules/buffer-writer/LICENSE

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

reverse_engineering/node_modules/buffer-writer/README.md

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

reverse_engineering/node_modules/buffer-writer/index.js

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

0 commit comments

Comments
 (0)