dbgate-api-premium 6.1.1 → 6.1.3
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 +7 -7
- package/src/controllers/connections.js +3 -3
- package/src/controllers/runners.js +8 -3
- package/src/currentVersion.js +2 -2
- package/src/gistSecret.js +1 -1
- package/src/proc/connectProcess.js +2 -2
- package/src/proc/serverConnectionProcess.js +3 -1
- package/src/proc/sshForwardProcess.js +3 -2
- package/src/utility/SSHConnection.js +4 -4
- package/src/utility/connectUtility.js +1 -1
- package/src/utility/directories.js +2 -2
- package/src/utility/processArgs.js +7 -3
- package/src/utility/sshTunnel.js +12 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api-premium",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "6.1.
|
|
4
|
+
"version": "6.1.3",
|
|
5
5
|
"homepage": "https://dbgate.org/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"compare-versions": "^3.6.0",
|
|
30
30
|
"cors": "^2.8.5",
|
|
31
31
|
"cross-env": "^6.0.3",
|
|
32
|
-
"dbgate-datalib": "^6.1.
|
|
33
|
-
"dbgate-query-splitter": "^4.11.
|
|
34
|
-
"dbgate-sqltree": "^6.1.
|
|
35
|
-
"dbgate-tools": "^6.1.
|
|
32
|
+
"dbgate-datalib": "^6.1.3",
|
|
33
|
+
"dbgate-query-splitter": "^4.11.3",
|
|
34
|
+
"dbgate-sqltree": "^6.1.3",
|
|
35
|
+
"dbgate-tools": "^6.1.3",
|
|
36
36
|
"debug": "^4.3.4",
|
|
37
37
|
"diff": "^5.0.0",
|
|
38
38
|
"diff2html": "^3.4.13",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"rimraf": "^3.0.0",
|
|
61
61
|
"semver": "^7.6.3",
|
|
62
62
|
"simple-encryptor": "^4.0.0",
|
|
63
|
-
"ssh2": "^1.
|
|
63
|
+
"ssh2": "^1.16.0",
|
|
64
64
|
"stream-json": "^1.8.0",
|
|
65
65
|
"tar": "^6.0.5"
|
|
66
66
|
},
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@types/fs-extra": "^9.0.11",
|
|
83
83
|
"@types/lodash": "^4.14.149",
|
|
84
|
-
"dbgate-types": "^6.1.
|
|
84
|
+
"dbgate-types": "^6.1.3",
|
|
85
85
|
"env-cmd": "^10.1.0",
|
|
86
86
|
"jsdoc-to-markdown": "^9.0.5",
|
|
87
87
|
"node-loader": "^1.0.2",
|
|
@@ -222,7 +222,7 @@ module.exports = {
|
|
|
222
222
|
},
|
|
223
223
|
|
|
224
224
|
test_meta: true,
|
|
225
|
-
test({ connection, requestDbList }) {
|
|
225
|
+
test({ connection, requestDbList = false }) {
|
|
226
226
|
const subprocess = fork(
|
|
227
227
|
global['API_PACKAGE'] || process.argv[1],
|
|
228
228
|
[
|
|
@@ -237,7 +237,7 @@ module.exports = {
|
|
|
237
237
|
}
|
|
238
238
|
);
|
|
239
239
|
pipeForkLogs(subprocess);
|
|
240
|
-
subprocess.send({ connection, requestDbList });
|
|
240
|
+
subprocess.send({ ...connection, requestDbList });
|
|
241
241
|
return new Promise(resolve => {
|
|
242
242
|
subprocess.on('message', resp => {
|
|
243
243
|
if (handleProcessCommunication(resp, subprocess)) return;
|
|
@@ -267,7 +267,7 @@ module.exports = {
|
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
if (test) {
|
|
270
|
-
const testRes = await this.test(res);
|
|
270
|
+
const testRes = await this.test({ connection: res });
|
|
271
271
|
if (testRes.msgtype == 'connected') {
|
|
272
272
|
volatileConnections[res._id] = res;
|
|
273
273
|
return {
|
|
@@ -49,7 +49,8 @@ logger.info('Finished job script');
|
|
|
49
49
|
dbgateApi.runScript(run);
|
|
50
50
|
`;
|
|
51
51
|
|
|
52
|
-
const loaderScriptTemplate = (functionName, props, runid) => `
|
|
52
|
+
const loaderScriptTemplate = (prefix, functionName, props, runid) => `
|
|
53
|
+
${prefix}
|
|
53
54
|
const dbgateApi = require(process.env.DBGATE_API);
|
|
54
55
|
dbgateApi.initializeApiEnvironment();
|
|
55
56
|
${requirePluginsTemplate(extractShellApiPlugins(functionName, props))}
|
|
@@ -149,7 +150,7 @@ module.exports = {
|
|
|
149
150
|
byline(subprocess.stdout).on('data', pipeDispatcher('info'));
|
|
150
151
|
byline(subprocess.stderr).on('data', pipeDispatcher('error'));
|
|
151
152
|
subprocess.on('exit', code => {
|
|
152
|
-
this.rejectRequest(runid, { message: 'No data
|
|
153
|
+
this.rejectRequest(runid, { message: 'No data returned, maybe input data source is too big' });
|
|
153
154
|
logger.info({ code, pid: subprocess.pid }, 'Exited process');
|
|
154
155
|
socket.emit(`runner-done-${runid}`, code);
|
|
155
156
|
});
|
|
@@ -224,10 +225,14 @@ module.exports = {
|
|
|
224
225
|
|
|
225
226
|
loadReader_meta: true,
|
|
226
227
|
async loadReader({ functionName, props }) {
|
|
228
|
+
const prefix = extractShellApiPlugins(functionName)
|
|
229
|
+
.map(packageName => `// @require ${packageName}\n`)
|
|
230
|
+
.join('');
|
|
231
|
+
|
|
227
232
|
const promise = new Promise((resolve, reject) => {
|
|
228
233
|
const runid = crypto.randomUUID();
|
|
229
234
|
this.requests[runid] = [resolve, reject];
|
|
230
|
-
this.startCore(runid, loaderScriptTemplate(functionName, props, runid));
|
|
235
|
+
this.startCore(runid, loaderScriptTemplate(prefix, functionName, props, runid));
|
|
231
236
|
});
|
|
232
237
|
return promise;
|
|
233
238
|
},
|
package/src/currentVersion.js
CHANGED
package/src/gistSecret.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
|
|
2
|
-
module.exports = '
|
|
2
|
+
module.exports = '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';
|
|
@@ -16,9 +16,9 @@ Platform: ${process.platform}
|
|
|
16
16
|
|
|
17
17
|
function start() {
|
|
18
18
|
childProcessChecker();
|
|
19
|
-
process.on('message', async
|
|
19
|
+
process.on('message', async connection => {
|
|
20
20
|
// @ts-ignore
|
|
21
|
-
const {
|
|
21
|
+
const { requestDbList } = connection;
|
|
22
22
|
if (handleProcessCommunication(connection)) return;
|
|
23
23
|
try {
|
|
24
24
|
const driver = requireEngineDriver(connection);
|
|
@@ -166,7 +166,9 @@ function start() {
|
|
|
166
166
|
if (time - lastPing > 40 * 1000) {
|
|
167
167
|
logger.info('Server connection not alive, exiting');
|
|
168
168
|
const driver = requireEngineDriver(storedConnection);
|
|
169
|
-
|
|
169
|
+
if (dbhan) {
|
|
170
|
+
await driver.close(dbhan);
|
|
171
|
+
}
|
|
170
172
|
process.exit(0);
|
|
171
173
|
}
|
|
172
174
|
}, 10 * 1000);
|
|
@@ -7,7 +7,7 @@ const { getLogger, extractErrorLogData, extractErrorMessage } = require('dbgate-
|
|
|
7
7
|
|
|
8
8
|
const logger = getLogger('sshProcess');
|
|
9
9
|
|
|
10
|
-
async function getSshConnection(connection) {
|
|
10
|
+
async function getSshConnection(connection, tunnelConfig) {
|
|
11
11
|
const sshConfig = {
|
|
12
12
|
endHost: connection.sshHost || '',
|
|
13
13
|
endPort: connection.sshPort || 22,
|
|
@@ -23,6 +23,7 @@ async function getSshConnection(connection) {
|
|
|
23
23
|
: undefined,
|
|
24
24
|
skipAutoPrivateKey: true,
|
|
25
25
|
noReadline: true,
|
|
26
|
+
bindHost: tunnelConfig.fromHost,
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
const sshConn = new SSHConnection(sshConfig);
|
|
@@ -31,7 +32,7 @@ async function getSshConnection(connection) {
|
|
|
31
32
|
|
|
32
33
|
async function handleStart({ connection, tunnelConfig }) {
|
|
33
34
|
try {
|
|
34
|
-
const sshConn = await getSshConnection(connection);
|
|
35
|
+
const sshConn = await getSshConnection(connection, tunnelConfig);
|
|
35
36
|
await sshConn.forward(tunnelConfig);
|
|
36
37
|
|
|
37
38
|
process.send({
|
|
@@ -130,7 +130,7 @@ class SSHConnection {
|
|
|
130
130
|
const connectionToBastion = await this.connect(bastionHost);
|
|
131
131
|
return new Promise((resolve, reject) => {
|
|
132
132
|
connectionToBastion.forwardOut(
|
|
133
|
-
|
|
133
|
+
this.options.bindHost,
|
|
134
134
|
22,
|
|
135
135
|
this.options.endHost,
|
|
136
136
|
this.options.endPort || 22,
|
|
@@ -228,9 +228,9 @@ class SSHConnection {
|
|
|
228
228
|
options.toPort
|
|
229
229
|
);
|
|
230
230
|
connection.forwardOut(
|
|
231
|
-
|
|
231
|
+
this.options.bindHost,
|
|
232
232
|
options.fromPort,
|
|
233
|
-
options.toHost ||
|
|
233
|
+
options.toHost || this.options.bindHost,
|
|
234
234
|
options.toPort,
|
|
235
235
|
(error, stream) => {
|
|
236
236
|
if (error) {
|
|
@@ -241,7 +241,7 @@ class SSHConnection {
|
|
|
241
241
|
}
|
|
242
242
|
);
|
|
243
243
|
})
|
|
244
|
-
.listen(options.fromPort,
|
|
244
|
+
.listen(options.fromPort, this.options.bindHost, () => {
|
|
245
245
|
return resolve();
|
|
246
246
|
});
|
|
247
247
|
});
|
|
@@ -97,7 +97,7 @@ function packagedPluginsDir() {
|
|
|
97
97
|
// }
|
|
98
98
|
}
|
|
99
99
|
if (processArgs.runE2eTests) {
|
|
100
|
-
return path.resolve('packer/build/plugins');
|
|
100
|
+
return path.resolve('packer/build/plugins');
|
|
101
101
|
}
|
|
102
102
|
return null;
|
|
103
103
|
}
|
|
@@ -113,7 +113,7 @@ function getPluginBackendPath(packageName) {
|
|
|
113
113
|
return path.join(packagedPluginsDir(), packageName, 'dist', 'backend.js');
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
const res = path.join(pluginsdir(), packageName, 'dist', 'backend.js')
|
|
116
|
+
const res = path.join(pluginsdir(), packageName, 'dist', 'backend.js');
|
|
117
117
|
if (fs.existsSync(res)) {
|
|
118
118
|
return res;
|
|
119
119
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
1
3
|
function getNamedArg(name) {
|
|
2
4
|
const argIndex = process.argv.indexOf(name);
|
|
3
5
|
if (argIndex > 0) {
|
|
@@ -20,13 +22,15 @@ function getPassArgs() {
|
|
|
20
22
|
const res = [];
|
|
21
23
|
if (global['PLUGINS_DIR']) {
|
|
22
24
|
res.push('--plugins-dir', global['PLUGINS_DIR']);
|
|
25
|
+
} else if (runE2eTests) {
|
|
26
|
+
res.push('--plugins-dir', path.resolve('packer/build/plugins'));
|
|
23
27
|
}
|
|
24
28
|
if (listenApiChild) {
|
|
25
29
|
res.push('listen-api-child');
|
|
26
30
|
}
|
|
27
|
-
if (runE2eTests) {
|
|
28
|
-
|
|
29
|
-
}
|
|
31
|
+
// if (runE2eTests) {
|
|
32
|
+
// res.push('--run-e2e-tests');
|
|
33
|
+
// }
|
|
30
34
|
return res;
|
|
31
35
|
}
|
|
32
36
|
|
package/src/utility/sshTunnel.js
CHANGED
|
@@ -43,33 +43,44 @@ function callForwardProcess(connection, tunnelConfig, tunnelCacheKey) {
|
|
|
43
43
|
logger.error(extractErrorLogData(err), 'Error connecting SSH');
|
|
44
44
|
}
|
|
45
45
|
return new Promise((resolve, reject) => {
|
|
46
|
+
let promiseHandled = false;
|
|
46
47
|
subprocess.on('message', resp => {
|
|
47
48
|
// @ts-ignore
|
|
48
49
|
const { msgtype, errorMessage } = resp;
|
|
49
50
|
if (msgtype == 'connected') {
|
|
50
51
|
resolve(subprocess);
|
|
52
|
+
promiseHandled = true;
|
|
51
53
|
}
|
|
52
54
|
if (msgtype == 'error') {
|
|
53
55
|
reject(new Error(errorMessage));
|
|
56
|
+
promiseHandled = true;
|
|
54
57
|
}
|
|
55
58
|
});
|
|
56
59
|
subprocess.on('exit', code => {
|
|
57
60
|
logger.info('SSH forward process exited');
|
|
58
61
|
delete sshTunnelCache[tunnelCacheKey];
|
|
62
|
+
if (!promiseHandled) {
|
|
63
|
+
reject(new Error('SSH forward process exited, try to change "Local host address for SSH connections" in Settings/Connections'));
|
|
64
|
+
}
|
|
59
65
|
});
|
|
60
66
|
});
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
async function getSshTunnel(connection) {
|
|
70
|
+
const config = require('../controllers/config');
|
|
71
|
+
|
|
64
72
|
const tunnelCacheKey = stableStringify(_.pick(connection, TUNNEL_FIELDS));
|
|
73
|
+
const globalSettings = await config.getSettings();
|
|
65
74
|
|
|
66
75
|
return await lock.acquire(tunnelCacheKey, async () => {
|
|
67
76
|
if (sshTunnelCache[tunnelCacheKey]) return sshTunnelCache[tunnelCacheKey];
|
|
68
77
|
const localPort = await portfinder.getPortPromise({ port: 10000, stopPort: 60000 });
|
|
78
|
+
const localHost = globalSettings?.['connection.sshBindHost'] || '127.0.0.1';
|
|
69
79
|
// workaround for `getPortPromise` not releasing the port quickly enough
|
|
70
80
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
71
81
|
const tunnelConfig = {
|
|
72
82
|
fromPort: localPort,
|
|
83
|
+
fromHost: localHost,
|
|
73
84
|
toPort: connection.port,
|
|
74
85
|
toHost: connection.server,
|
|
75
86
|
};
|
|
@@ -87,6 +98,7 @@ async function getSshTunnel(connection) {
|
|
|
87
98
|
sshTunnelCache[tunnelCacheKey] = {
|
|
88
99
|
state: 'ok',
|
|
89
100
|
localPort,
|
|
101
|
+
localHost,
|
|
90
102
|
subprocess,
|
|
91
103
|
};
|
|
92
104
|
return sshTunnelCache[tunnelCacheKey];
|