dbgate-api 4.4.5-alpha.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/controllers/connections.js +25 -15
- package/src/controllers/databaseConnections.js +1 -0
- package/src/currentVersion.js +2 -2
- package/src/proc/connectProcess.js +1 -9
- package/src/utility/crypting.js +11 -0
- package/src/utility/getChartExport.js +3 -0
- package/src/utility/requireEngineDriver.js +3 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.5.0",
|
|
5
5
|
"homepage": "https://dbgate.org/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"compare-versions": "^3.6.0",
|
|
26
26
|
"cors": "^2.8.5",
|
|
27
27
|
"cross-env": "^6.0.3",
|
|
28
|
-
"dbgate-query-splitter": "^4.
|
|
29
|
-
"dbgate-sqltree": "^4.
|
|
30
|
-
"dbgate-tools": "^4.
|
|
28
|
+
"dbgate-query-splitter": "^4.5.0",
|
|
29
|
+
"dbgate-sqltree": "^4.5.0",
|
|
30
|
+
"dbgate-tools": "^4.5.0",
|
|
31
31
|
"diff": "^5.0.0",
|
|
32
32
|
"diff2html": "^3.4.13",
|
|
33
33
|
"eslint": "^6.8.0",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/fs-extra": "^9.0.11",
|
|
66
66
|
"@types/lodash": "^4.14.149",
|
|
67
|
-
"dbgate-types": "^4.
|
|
67
|
+
"dbgate-types": "^4.5.0",
|
|
68
68
|
"env-cmd": "^10.1.0",
|
|
69
69
|
"node-loader": "^1.0.2",
|
|
70
70
|
"nodemon": "^2.0.2",
|
|
@@ -8,6 +8,7 @@ const { datadir, filesdir } = require('../utility/directories');
|
|
|
8
8
|
const socket = require('../utility/socket');
|
|
9
9
|
const { encryptConnection } = require('../utility/crypting');
|
|
10
10
|
const { handleProcessCommunication } = require('../utility/processComm');
|
|
11
|
+
const { pickSafeConnectionInfo } = require('../utility/crypting');
|
|
11
12
|
|
|
12
13
|
const processArgs = require('../utility/processArgs');
|
|
13
14
|
|
|
@@ -39,7 +40,7 @@ function getDatabaseFileLabel(databaseFile) {
|
|
|
39
40
|
|
|
40
41
|
function getPortalCollections() {
|
|
41
42
|
if (process.env.CONNECTIONS) {
|
|
42
|
-
|
|
43
|
+
const connections = _.compact(process.env.CONNECTIONS.split(',')).map(id => ({
|
|
43
44
|
_id: id,
|
|
44
45
|
engine: process.env[`ENGINE_${id}`],
|
|
45
46
|
server: process.env[`SERVER_${id}`],
|
|
@@ -53,6 +54,16 @@ function getPortalCollections() {
|
|
|
53
54
|
singleDatabase: !!process.env[`DATABASE_${id}`],
|
|
54
55
|
displayName: process.env[`LABEL_${id}`],
|
|
55
56
|
}));
|
|
57
|
+
console.log('Using connections from ENV variables:');
|
|
58
|
+
console.log(JSON.stringify(connections.map(pickSafeConnectionInfo), undefined, 2));
|
|
59
|
+
const noengine = connections.filter(x => !x.engine);
|
|
60
|
+
if (noengine.length > 0) {
|
|
61
|
+
console.log(
|
|
62
|
+
'Warning: Invalid CONNECTIONS configutation, missing ENGINE for connection ID:',
|
|
63
|
+
noengine.map(x => x._id)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return connections;
|
|
56
67
|
}
|
|
57
68
|
|
|
58
69
|
const args = getNamedArgs();
|
|
@@ -134,11 +145,8 @@ module.exports = {
|
|
|
134
145
|
return portalConnections || this.datastore.find();
|
|
135
146
|
},
|
|
136
147
|
|
|
137
|
-
test_meta:
|
|
138
|
-
|
|
139
|
-
raw: true,
|
|
140
|
-
},
|
|
141
|
-
test(req, res) {
|
|
148
|
+
test_meta: true,
|
|
149
|
+
test(connection) {
|
|
142
150
|
const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
|
|
143
151
|
'--is-forked-api',
|
|
144
152
|
'--start-process',
|
|
@@ -146,15 +154,17 @@ module.exports = {
|
|
|
146
154
|
...processArgs.getPassArgs(),
|
|
147
155
|
// ...process.argv.slice(3),
|
|
148
156
|
]);
|
|
149
|
-
subprocess.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
subprocess.send(connection);
|
|
158
|
+
return new Promise(resolve => {
|
|
159
|
+
subprocess.on('message', resp => {
|
|
160
|
+
if (handleProcessCommunication(resp, subprocess)) return;
|
|
161
|
+
// @ts-ignore
|
|
162
|
+
const { msgtype } = resp;
|
|
163
|
+
if (msgtype == 'connected' || msgtype == 'error') {
|
|
164
|
+
resolve(resp);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
156
167
|
});
|
|
157
|
-
subprocess.send(req.body);
|
|
158
168
|
},
|
|
159
169
|
|
|
160
170
|
save_meta: true,
|
|
@@ -204,7 +214,7 @@ module.exports = {
|
|
|
204
214
|
|
|
205
215
|
get_meta: true,
|
|
206
216
|
async get({ conid }) {
|
|
207
|
-
if (portalConnections) return portalConnections.find(x => x._id == conid);
|
|
217
|
+
if (portalConnections) return portalConnections.find(x => x._id == conid) || null;
|
|
208
218
|
const res = await this.datastore.find({ _id: conid });
|
|
209
219
|
return res[0] || null;
|
|
210
220
|
},
|
package/src/currentVersion.js
CHANGED
|
@@ -2,17 +2,9 @@ const childProcessChecker = require('../utility/childProcessChecker');
|
|
|
2
2
|
const requireEngineDriver = require('../utility/requireEngineDriver');
|
|
3
3
|
const connectUtility = require('../utility/connectUtility');
|
|
4
4
|
const { handleProcessCommunication } = require('../utility/processComm');
|
|
5
|
+
const { pickSafeConnectionInfo } = require('../utility/crypting');
|
|
5
6
|
const _ = require('lodash');
|
|
6
7
|
|
|
7
|
-
function pickSafeConnectionInfo(connection) {
|
|
8
|
-
return _.mapValues(connection, (v, k) => {
|
|
9
|
-
if (k == 'engine' || k == 'port' || k == 'authType' || k == 'sshMode' || k == 'passwordMode') return v;
|
|
10
|
-
if (v === null || v === true || v === false) return v;
|
|
11
|
-
if (v) return '***';
|
|
12
|
-
return undefined;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
8
|
const formatErrorDetail = (e, connection) => `${e.stack}
|
|
17
9
|
|
|
18
10
|
Error JSON: ${JSON.stringify(e, undefined, 2)}
|
package/src/utility/crypting.js
CHANGED
|
@@ -2,6 +2,7 @@ const crypto = require('crypto');
|
|
|
2
2
|
const simpleEncryptor = require('simple-encryptor');
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const _ = require('lodash');
|
|
5
6
|
|
|
6
7
|
const { datadir } = require('./directories');
|
|
7
8
|
|
|
@@ -81,8 +82,18 @@ function decryptConnection(connection) {
|
|
|
81
82
|
return connection;
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
function pickSafeConnectionInfo(connection) {
|
|
86
|
+
return _.mapValues(connection, (v, k) => {
|
|
87
|
+
if (k == 'engine' || k == 'port' || k == 'authType' || k == 'sshMode' || k == 'passwordMode') return v;
|
|
88
|
+
if (v === null || v === true || v === false) return v;
|
|
89
|
+
if (v) return '***';
|
|
90
|
+
return undefined;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
84
94
|
module.exports = {
|
|
85
95
|
loadEncryptionKey,
|
|
86
96
|
encryptConnection,
|
|
87
97
|
decryptConnection,
|
|
98
|
+
pickSafeConnectionInfo,
|
|
88
99
|
};
|
|
@@ -7,6 +7,9 @@ const getChartExport = (title, config, imageFile) => {
|
|
|
7
7
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.min.js" integrity="sha512-GMGzUEevhWh8Tc/njS0bDpwgxdCJLQBWG3Z2Ct+JGOpVnEmjvNx6ts4v6A2XJf1HOrtOsfhv3hBKpK9kE5z8AQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
|
8
8
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
|
9
9
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-adapter-moment/1.0.0/chartjs-adapter-moment.min.js" integrity="sha512-oh5t+CdSBsaVVAvxcZKy3XJdP7ZbYUBSRCXDTVn0ODewMDDNnELsrG9eDm8rVZAQg7RsDD/8K3MjPAFB13o6eA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
|
10
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js" integrity="sha512-UXumZrZNiOwnTcZSHLOfcTs0aos2MzBWHXOHOuB0J/R44QB0dwY5JgfbvljXcklVf65Gc4El6RjZ+lnwd2az2g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
|
11
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-zoom/1.2.0/chartjs-plugin-zoom.min.js" integrity="sha512-TT0wAMqqtjXVzpc48sI0G84rBP+oTkBZPgeRYIOVRGUdwJsyS3WPipsNh///ay2LJ+onCM23tipnz6EvEy2/UA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
|
12
|
+
|
|
10
13
|
<style>
|
|
11
14
|
a { text-decoration: none }
|
|
12
15
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
2
|
const requirePlugin = require('../shell/requirePlugin');
|
|
3
|
+
const { pickSafeConnectionInfo } = require('./crypting');
|
|
3
4
|
|
|
4
5
|
/** @returns {import('dbgate-types').EngineDriver} */
|
|
5
6
|
function requireEngineDriver(connection) {
|
|
@@ -10,14 +11,14 @@ function requireEngineDriver(connection) {
|
|
|
10
11
|
engine = connection.engine;
|
|
11
12
|
}
|
|
12
13
|
if (!engine) {
|
|
13
|
-
throw new Error(
|
|
14
|
+
throw new Error(`Could not get driver from connection ${JSON.stringify(pickSafeConnectionInfo(connection))}`);
|
|
14
15
|
}
|
|
15
16
|
if (engine.includes('@')) {
|
|
16
17
|
const [shortName, packageName] = engine.split('@');
|
|
17
18
|
const plugin = requirePlugin(packageName);
|
|
18
19
|
return plugin.drivers.find(x => x.engine == engine);
|
|
19
20
|
}
|
|
20
|
-
throw new Error(`Could not
|
|
21
|
+
throw new Error(`Could not find engine driver ${engine}`);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
module.exports = requireEngineDriver;
|