dbgate-api-premium 7.0.6 → 7.1.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 +7 -6
- package/src/controllers/connections.js +2 -2
- package/src/controllers/databaseConnections.js +5 -0
- package/src/controllers/restConnections.js +316 -0
- package/src/controllers/runners.js +10 -10
- package/src/controllers/storage.js +4 -4
- package/src/currentVersion.js +2 -2
- package/src/main.js +2 -0
- package/src/proc/connectProcess.js +4 -1
- package/src/proc/index.js +2 -0
- package/src/proc/restConnectionProcess.js +771 -0
- package/src/shell/requirePlugin.js +9 -3
- package/src/storageModel.js +78 -78
- package/src/utility/connectUtility.js +29 -1
- package/src/utility/crypting.js +21 -1
- package/src/utility/envtools.js +13 -2
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api-premium",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "7.0
|
|
5
|
-
"homepage": "https://dbgate.
|
|
4
|
+
"version": "7.1.0",
|
|
5
|
+
"homepage": "https://www.dbgate.io/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/dbgate/dbgate.git"
|
|
@@ -30,10 +30,11 @@
|
|
|
30
30
|
"compare-versions": "^3.6.0",
|
|
31
31
|
"cors": "^2.8.5",
|
|
32
32
|
"cross-env": "^6.0.3",
|
|
33
|
-
"dbgate-datalib": "^7.0
|
|
33
|
+
"dbgate-datalib": "^7.1.0",
|
|
34
34
|
"dbgate-query-splitter": "^4.11.9",
|
|
35
|
-
"dbgate-
|
|
36
|
-
"dbgate-
|
|
35
|
+
"dbgate-rest": "^7.1.0",
|
|
36
|
+
"dbgate-sqltree": "^7.1.0",
|
|
37
|
+
"dbgate-tools": "^7.1.0",
|
|
37
38
|
"debug": "^4.3.4",
|
|
38
39
|
"diff": "^5.0.0",
|
|
39
40
|
"diff2html": "^3.4.13",
|
|
@@ -87,7 +88,7 @@
|
|
|
87
88
|
"devDependencies": {
|
|
88
89
|
"@types/fs-extra": "^9.0.11",
|
|
89
90
|
"@types/lodash": "^4.14.149",
|
|
90
|
-
"dbgate-types": "^7.0
|
|
91
|
+
"dbgate-types": "^7.1.0",
|
|
91
92
|
"env-cmd": "^10.1.0",
|
|
92
93
|
"jsdoc-to-markdown": "^9.0.5",
|
|
93
94
|
"node-loader": "^1.0.2",
|
|
@@ -202,7 +202,7 @@ module.exports = {
|
|
|
202
202
|
|
|
203
203
|
const storageConnections = await storage.connections(req);
|
|
204
204
|
if (storageConnections) {
|
|
205
|
-
return storageConnections;
|
|
205
|
+
return storageConnections.map(maskConnection);
|
|
206
206
|
}
|
|
207
207
|
if (portalConnections) {
|
|
208
208
|
if (platformInfo.allowShellConnection) return portalConnections.map(x => encryptConnection(x));
|
|
@@ -484,7 +484,7 @@ module.exports = {
|
|
|
484
484
|
|
|
485
485
|
const storageConnection = await storage.getConnection({ conid });
|
|
486
486
|
if (storageConnection) {
|
|
487
|
-
return storageConnection;
|
|
487
|
+
return mask ? maskConnection(storageConnection) : storageConnection;
|
|
488
488
|
}
|
|
489
489
|
|
|
490
490
|
if (portalConnections) {
|
|
@@ -165,6 +165,11 @@ module.exports = {
|
|
|
165
165
|
if (!connection) {
|
|
166
166
|
throw new Error(`databaseConnections: Connection with conid="${conid}" not found`);
|
|
167
167
|
}
|
|
168
|
+
|
|
169
|
+
if (connection.engine?.endsWith('@rest')) {
|
|
170
|
+
return { isApiConnection: true };
|
|
171
|
+
}
|
|
172
|
+
|
|
168
173
|
if (connection.passwordMode == 'askPassword' || connection.passwordMode == 'askUser') {
|
|
169
174
|
throw new MissingCredentialsError({ conid, passwordMode: connection.passwordMode });
|
|
170
175
|
}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
// *** This file is part of DbGate Premium ***
|
|
2
|
+
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const connections = require('./connections');
|
|
5
|
+
const socket = require('../utility/socket');
|
|
6
|
+
const { fork } = require('child_process');
|
|
7
|
+
const _ = require('lodash');
|
|
8
|
+
const AsyncLock = require('async-lock');
|
|
9
|
+
const { handleProcessCommunication } = require('../utility/processComm');
|
|
10
|
+
const lock = new AsyncLock();
|
|
11
|
+
const config = require('./config');
|
|
12
|
+
const processArgs = require('../utility/processArgs');
|
|
13
|
+
const { testConnectionPermission, loadPermissionsFromRequest, hasPermission } = require('../utility/hasPermission');
|
|
14
|
+
const { MissingCredentialsError } = require('../utility/exceptions');
|
|
15
|
+
const pipeForkLogs = require('../utility/pipeForkLogs');
|
|
16
|
+
const { getLogger, extractErrorLogData } = require('dbgate-tools');
|
|
17
|
+
const { sendToAuditLog } = require('../utility/auditlog');
|
|
18
|
+
const { decryptPasswordString } = require('../utility/crypting');
|
|
19
|
+
const { getRestAuthFromConnection } = require('../utility/connectUtility');
|
|
20
|
+
|
|
21
|
+
const logger = getLogger('restConnection');
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
opened: [],
|
|
25
|
+
closed: {},
|
|
26
|
+
requests: {},
|
|
27
|
+
|
|
28
|
+
handle_apiInfo(conid, { apiInfo }) {
|
|
29
|
+
const existing = this.opened.find(x => x.conid == conid);
|
|
30
|
+
if (!existing) return;
|
|
31
|
+
existing.apiInfo = apiInfo;
|
|
32
|
+
socket.emitChanged(`rest-api-info-changed`, { conid });
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
handle_status(conid, { status }) {
|
|
36
|
+
const existing = this.opened.find(x => x.conid == conid);
|
|
37
|
+
if (!existing) return;
|
|
38
|
+
if (existing.status && status && existing.status.counter > status.counter) return;
|
|
39
|
+
existing.status = status;
|
|
40
|
+
socket.emitChanged(`rest-status-changed`, { conid });
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
handle_ping() {},
|
|
44
|
+
|
|
45
|
+
handle_response(conid, { msgid, ...response }) {
|
|
46
|
+
const pending = this.requests[msgid];
|
|
47
|
+
if (!pending) {
|
|
48
|
+
logger.warn(
|
|
49
|
+
`DBGM-00275 restConnections: Received response for unknown or already handled msgid="${msgid}" (conid="${conid}")`
|
|
50
|
+
);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const [resolve, reject] = pending;
|
|
54
|
+
resolve(response);
|
|
55
|
+
delete this.requests[msgid];
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
async ensureOpened(conid) {
|
|
59
|
+
const res = await lock.acquire(conid, async () => {
|
|
60
|
+
const existing = this.opened.find(x => x.conid == conid);
|
|
61
|
+
if (existing) return existing;
|
|
62
|
+
|
|
63
|
+
const connection = await connections.getCore({ conid });
|
|
64
|
+
if (!connection) {
|
|
65
|
+
throw new Error(`restConnections: Connection with conid="${conid}" not found`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (connection.passwordMode == 'askPassword' || connection.passwordMode == 'askUser') {
|
|
69
|
+
throw new MissingCredentialsError({ conid, passwordMode: connection.passwordMode });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const subprocess = fork(
|
|
73
|
+
global['API_PACKAGE'] || process.argv[1],
|
|
74
|
+
['--is-forked-api', '--start-process', 'restConnectionProcess', ...processArgs.getPassArgs()],
|
|
75
|
+
{
|
|
76
|
+
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
pipeForkLogs(subprocess);
|
|
81
|
+
|
|
82
|
+
const newOpened = {
|
|
83
|
+
conid,
|
|
84
|
+
subprocess,
|
|
85
|
+
apiInfo: null,
|
|
86
|
+
connection,
|
|
87
|
+
status: {
|
|
88
|
+
name: 'pending',
|
|
89
|
+
},
|
|
90
|
+
disconnected: false,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
this.opened.push(newOpened);
|
|
94
|
+
delete this.closed[conid];
|
|
95
|
+
socket.emitChanged(`rest-status-changed`, { conid });
|
|
96
|
+
|
|
97
|
+
subprocess.on('message', message => {
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
const { msgtype } = message;
|
|
100
|
+
if (handleProcessCommunication(message, subprocess)) return;
|
|
101
|
+
if (newOpened.disconnected) return;
|
|
102
|
+
const funcName = `handle_${msgtype}`;
|
|
103
|
+
if (!this[funcName]) {
|
|
104
|
+
logger.error({ msgtype, conid }, 'DBGM-00276 Unknown message type from subprocess restConnectionProcess');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this[funcName](conid, message);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
subprocess.on('exit', () => {
|
|
111
|
+
if (newOpened.disconnected) return;
|
|
112
|
+
this.close(conid, false);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
subprocess.on('error', err => {
|
|
116
|
+
logger.error(extractErrorLogData(err), 'DBGM-00277 Error in REST connection subprocess');
|
|
117
|
+
if (newOpened.disconnected) return;
|
|
118
|
+
this.close(conid, false);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
subprocess.send({
|
|
122
|
+
msgtype: 'connect',
|
|
123
|
+
connection: { ...connection, restAuth: getRestAuthFromConnection(connection) },
|
|
124
|
+
globalSettings: await config.getSettings(),
|
|
125
|
+
});
|
|
126
|
+
return newOpened;
|
|
127
|
+
});
|
|
128
|
+
return res;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
close(conid, kill = true) {
|
|
132
|
+
const existing = this.opened.find(x => x.conid == conid);
|
|
133
|
+
if (existing) {
|
|
134
|
+
existing.disconnected = true;
|
|
135
|
+
if (kill) {
|
|
136
|
+
try {
|
|
137
|
+
existing.subprocess.kill();
|
|
138
|
+
} catch (err) {
|
|
139
|
+
logger.error(extractErrorLogData(err), 'DBGM-00278 Error killing REST subprocess');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
this.opened = this.opened.filter(x => x.conid != conid);
|
|
143
|
+
this.closed[conid] = {
|
|
144
|
+
...existing.status,
|
|
145
|
+
name: 'error',
|
|
146
|
+
};
|
|
147
|
+
socket.emitChanged(`rest-status-changed`, { conid });
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
disconnect_meta: true,
|
|
152
|
+
async disconnect({ conid }, req) {
|
|
153
|
+
await testConnectionPermission(conid, req);
|
|
154
|
+
await this.close(conid, true);
|
|
155
|
+
return { status: 'ok' };
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
getApiInfo_meta: true,
|
|
159
|
+
async getApiInfo({ conid }, req) {
|
|
160
|
+
if (!conid) return null;
|
|
161
|
+
|
|
162
|
+
await testConnectionPermission(conid, req);
|
|
163
|
+
|
|
164
|
+
const opened = await this.ensureOpened(conid);
|
|
165
|
+
sendToAuditLog(req, {
|
|
166
|
+
category: 'restop',
|
|
167
|
+
component: 'RestConnectionsController',
|
|
168
|
+
action: 'getApiInfo',
|
|
169
|
+
event: 'rest.getApiInfo',
|
|
170
|
+
severity: 'info',
|
|
171
|
+
conid,
|
|
172
|
+
sessionParam: `${conid}`,
|
|
173
|
+
sessionGroup: 'getApiInfo',
|
|
174
|
+
message: `Loaded API info for REST connection`,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return opened?.apiInfo ?? null;
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
restStatus_meta: true,
|
|
181
|
+
async restStatus() {
|
|
182
|
+
return {
|
|
183
|
+
...this.closed,
|
|
184
|
+
..._.mapValues(_.keyBy(this.opened, 'conid'), 'status'),
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
ping_meta: true,
|
|
189
|
+
async ping({ conidArray, strmid }) {
|
|
190
|
+
await Promise.all(
|
|
191
|
+
_.uniq(conidArray).map(async conid => {
|
|
192
|
+
try {
|
|
193
|
+
const opened = await this.ensureOpened(conid);
|
|
194
|
+
if (!opened) {
|
|
195
|
+
return Promise.resolve();
|
|
196
|
+
}
|
|
197
|
+
opened.subprocess.send({ msgtype: 'ping' });
|
|
198
|
+
} catch (err) {
|
|
199
|
+
logger.error(extractErrorLogData(err), 'DBGM-00279 Error pinging REST connection');
|
|
200
|
+
this.close(conid);
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
socket.setStreamIdFilter(strmid, { conid: conidArray ?? [] });
|
|
205
|
+
return { status: 'ok' };
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
refresh_meta: true,
|
|
209
|
+
async refresh({ conid, keepOpen }, req) {
|
|
210
|
+
await testConnectionPermission(conid, req);
|
|
211
|
+
if (!keepOpen) this.close(conid);
|
|
212
|
+
|
|
213
|
+
const opened = await this.ensureOpened(conid);
|
|
214
|
+
return this.sendRequest(opened, { msgtype: 'refresh' });
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
testConnection_meta: true,
|
|
218
|
+
async testConnection({ conid }, req) {
|
|
219
|
+
await testConnectionPermission(conid, req);
|
|
220
|
+
const opened = await this.ensureOpened(conid);
|
|
221
|
+
if (!opened) {
|
|
222
|
+
return { errorMessage: 'Could not open REST connection' };
|
|
223
|
+
}
|
|
224
|
+
const res = await this.sendRequest(opened, { msgtype: 'testConnection' });
|
|
225
|
+
if (res.errorMessage) {
|
|
226
|
+
return {
|
|
227
|
+
errorMessage: res.errorMessage,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return { status: 'ok' };
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
async executeCore(msgtype, { conid, method, endpoint, parameters, server }, req) {
|
|
234
|
+
await testConnectionPermission(conid, req);
|
|
235
|
+
const opened = await this.ensureOpened(conid);
|
|
236
|
+
if (!opened) {
|
|
237
|
+
return { errorMessage: 'Could not open REST connection' };
|
|
238
|
+
}
|
|
239
|
+
const auth = getRestAuthFromConnection(opened.connection);
|
|
240
|
+
return this.sendRequest(opened, {
|
|
241
|
+
msgtype,
|
|
242
|
+
method,
|
|
243
|
+
endpoint,
|
|
244
|
+
parameters,
|
|
245
|
+
server,
|
|
246
|
+
auth,
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
executeOpenapi_meta: true,
|
|
251
|
+
async executeOpenapi({ conid, method, endpoint, parameters, server }, req) {
|
|
252
|
+
return this.executeCore('executeOpenapi', { conid, method, endpoint, parameters, server }, req);
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
executeOdata_meta: true,
|
|
256
|
+
async executeOdata({ conid, method, endpoint, parameters, server }, req) {
|
|
257
|
+
return this.executeCore('executeOdata', { conid, method, endpoint, parameters, server }, req);
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
apiQuery_meta: true,
|
|
261
|
+
async apiQuery({ conid, server, query, variables }, req) {
|
|
262
|
+
await testConnectionPermission(conid, req);
|
|
263
|
+
const opened = await this.ensureOpened(conid);
|
|
264
|
+
if (!opened) {
|
|
265
|
+
return { errorMessage: 'Could not open REST connection' };
|
|
266
|
+
}
|
|
267
|
+
const auth = getRestAuthFromConnection(opened.connection);
|
|
268
|
+
const res = await this.sendRequest(opened, {
|
|
269
|
+
msgtype: 'apiQuery',
|
|
270
|
+
server,
|
|
271
|
+
query,
|
|
272
|
+
variables,
|
|
273
|
+
auth,
|
|
274
|
+
});
|
|
275
|
+
return res;
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
loadGraphqlConnectionData_meta: true,
|
|
279
|
+
async loadGraphqlConnectionData(
|
|
280
|
+
{ conid, server, operationName, projection, queryField, selectedFieldSelection, pageSize, filterParameterName, filterValue },
|
|
281
|
+
req
|
|
282
|
+
) {
|
|
283
|
+
await testConnectionPermission(conid, req);
|
|
284
|
+
const opened = await this.ensureOpened(conid);
|
|
285
|
+
if (!opened) {
|
|
286
|
+
return { errorMessage: 'Could not open REST connection' };
|
|
287
|
+
}
|
|
288
|
+
const auth = getRestAuthFromConnection(opened.connection);
|
|
289
|
+
return this.sendRequest(opened, {
|
|
290
|
+
msgtype: 'loadGraphqlConnectionData',
|
|
291
|
+
server,
|
|
292
|
+
operationName,
|
|
293
|
+
projection,
|
|
294
|
+
queryField,
|
|
295
|
+
selectedFieldSelection,
|
|
296
|
+
pageSize,
|
|
297
|
+
filterParameterName,
|
|
298
|
+
filterValue,
|
|
299
|
+
auth,
|
|
300
|
+
});
|
|
301
|
+
},
|
|
302
|
+
|
|
303
|
+
sendRequest(conn, message) {
|
|
304
|
+
const msgid = crypto.randomUUID();
|
|
305
|
+
const promise = new Promise((resolve, reject) => {
|
|
306
|
+
this.requests[msgid] = [resolve, reject];
|
|
307
|
+
try {
|
|
308
|
+
conn.subprocess.send({ msgid, ...message });
|
|
309
|
+
} catch (err) {
|
|
310
|
+
logger.error(extractErrorLogData(err), 'DBGM-00280 Error sending request to REST connection');
|
|
311
|
+
this.close(conn.conid);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
return promise;
|
|
315
|
+
},
|
|
316
|
+
};
|
|
@@ -172,7 +172,7 @@ module.exports = {
|
|
|
172
172
|
byline(subprocess.stderr).on('data', pipeDispatcher('error'));
|
|
173
173
|
subprocess.on('exit', code => {
|
|
174
174
|
// console.log('... EXITED', code);
|
|
175
|
-
this.rejectRequest(runid, { message: 'No data returned, maybe input data source is too big' });
|
|
175
|
+
this.rejectRequest(runid, { message: 'DBGM-00281 No data returned, maybe input data source is too big' });
|
|
176
176
|
logger.info({ code, pid: subprocess.pid }, 'DBGM-00016 Exited process');
|
|
177
177
|
socket.emit(`runner-done-${runid}`, code);
|
|
178
178
|
this.opened = this.opened.filter(x => x.runid != runid);
|
|
@@ -225,7 +225,7 @@ module.exports = {
|
|
|
225
225
|
subprocess.on('exit', code => {
|
|
226
226
|
console.log('... EXITED', code);
|
|
227
227
|
logger.info({ code, pid: subprocess.pid }, 'DBGM-00017 Exited process');
|
|
228
|
-
this.dispatchMessage(runid, `Finished external process with code ${code}`);
|
|
228
|
+
this.dispatchMessage(runid, `DBGM-00282 Finished external process with code ${code}`);
|
|
229
229
|
socket.emit(`runner-done-${runid}`, code);
|
|
230
230
|
if (onFinished) {
|
|
231
231
|
onFinished();
|
|
@@ -233,7 +233,7 @@ module.exports = {
|
|
|
233
233
|
this.opened = this.opened.filter(x => x.runid != runid);
|
|
234
234
|
});
|
|
235
235
|
subprocess.on('spawn', () => {
|
|
236
|
-
this.dispatchMessage(runid, `Started external process ${command}`);
|
|
236
|
+
this.dispatchMessage(runid, `DBGM-00283 Started external process ${command}`);
|
|
237
237
|
});
|
|
238
238
|
subprocess.on('error', error => {
|
|
239
239
|
console.log('... ERROR subprocess', error);
|
|
@@ -279,7 +279,7 @@ module.exports = {
|
|
|
279
279
|
if (script.type == 'json') {
|
|
280
280
|
if (!platformInfo.isElectron) {
|
|
281
281
|
if (!checkSecureDirectoriesInScript(script)) {
|
|
282
|
-
return { errorMessage: 'Unallowed directories in script' };
|
|
282
|
+
return { errorMessage: 'DBGM-00284 Unallowed directories in script' };
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
|
|
@@ -299,10 +299,10 @@ module.exports = {
|
|
|
299
299
|
action: 'script',
|
|
300
300
|
severity: 'warn',
|
|
301
301
|
detail: script,
|
|
302
|
-
message: 'Scripts are not allowed',
|
|
302
|
+
message: 'DBGM-00285 Scripts are not allowed',
|
|
303
303
|
});
|
|
304
304
|
|
|
305
|
-
return { errorMessage: 'Shell scripting is not allowed' };
|
|
305
|
+
return { errorMessage: 'DBGM-00286 Shell scripting is not allowed' };
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
sendToAuditLog(req, {
|
|
@@ -312,7 +312,7 @@ module.exports = {
|
|
|
312
312
|
action: 'script',
|
|
313
313
|
severity: 'info',
|
|
314
314
|
detail: script,
|
|
315
|
-
message: 'Running JS script',
|
|
315
|
+
message: 'DBGM-00287 Running JS script',
|
|
316
316
|
});
|
|
317
317
|
|
|
318
318
|
return this.startCore(runid, scriptTemplate(script, false));
|
|
@@ -327,7 +327,7 @@ module.exports = {
|
|
|
327
327
|
async cancel({ runid }) {
|
|
328
328
|
const runner = this.opened.find(x => x.runid == runid);
|
|
329
329
|
if (!runner) {
|
|
330
|
-
throw new Error('Invalid runner');
|
|
330
|
+
throw new Error('DBGM-00288 Invalid runner');
|
|
331
331
|
}
|
|
332
332
|
runner.subprocess.kill();
|
|
333
333
|
return { state: 'ok' };
|
|
@@ -353,7 +353,7 @@ module.exports = {
|
|
|
353
353
|
async loadReader({ functionName, props }) {
|
|
354
354
|
if (!platformInfo.isElectron) {
|
|
355
355
|
if (props?.fileName && !checkSecureDirectories(props.fileName)) {
|
|
356
|
-
return { errorMessage: 'Unallowed file' };
|
|
356
|
+
return { errorMessage: 'DBGM-00289 Unallowed file' };
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
const prefix = extractShellApiPlugins(functionName)
|
|
@@ -371,7 +371,7 @@ module.exports = {
|
|
|
371
371
|
scriptResult_meta: true,
|
|
372
372
|
async scriptResult({ script }) {
|
|
373
373
|
if (script.type != 'json') {
|
|
374
|
-
return { errorMessage: 'Only JSON scripts are allowed' };
|
|
374
|
+
return { errorMessage: 'DBGM-00290 Only JSON scripts are allowed' };
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
const promise = new Promise(async (resolve, reject) => {
|
|
@@ -1173,7 +1173,7 @@ module.exports = {
|
|
|
1173
1173
|
|
|
1174
1174
|
// Store token in database
|
|
1175
1175
|
await storageSqlCommandFmt(
|
|
1176
|
-
'insert into ~
|
|
1176
|
+
'insert into ~user_password_reset_tokens (~user_id, ~token, ~created_at, ~expires_at) values (%v, %v, %v, %v)',
|
|
1177
1177
|
user.id,
|
|
1178
1178
|
token,
|
|
1179
1179
|
format(now, "yyyy-MM-dd'T'HH:mm:ss"),
|
|
@@ -1219,7 +1219,7 @@ DbGate Team
|
|
|
1219
1219
|
// Cleanup: delete the password reset token that was inserted before sending the email
|
|
1220
1220
|
try {
|
|
1221
1221
|
await storageSqlCommandFmt(
|
|
1222
|
-
'delete from ~
|
|
1222
|
+
'delete from ~user_password_reset_tokens where ~token = %v and ~used_at is null',
|
|
1223
1223
|
token
|
|
1224
1224
|
);
|
|
1225
1225
|
} catch (cleanupErr) {
|
|
@@ -1238,7 +1238,7 @@ DbGate Team
|
|
|
1238
1238
|
async resetPassword({ token, newPassword }, req) {
|
|
1239
1239
|
// Find valid token
|
|
1240
1240
|
const tokens = await storageSelectFmt(
|
|
1241
|
-
'select * from ~
|
|
1241
|
+
'select * from ~user_password_reset_tokens where ~token = %v and ~used_at is null and ~expires_at > %v',
|
|
1242
1242
|
token,
|
|
1243
1243
|
format(new Date(), "yyyy-MM-dd'T'HH:mm:ss")
|
|
1244
1244
|
);
|
|
@@ -1265,7 +1265,7 @@ DbGate Team
|
|
|
1265
1265
|
|
|
1266
1266
|
// Mark token as used
|
|
1267
1267
|
await storageSqlCommandFmt(
|
|
1268
|
-
'update ~
|
|
1268
|
+
'update ~user_password_reset_tokens set ~used_at = %v where ~id = %v',
|
|
1269
1269
|
format(new Date(), "yyyy-MM-dd'T'HH:mm:ss"),
|
|
1270
1270
|
resetToken.id
|
|
1271
1271
|
);
|
package/src/currentVersion.js
CHANGED
package/src/main.js
CHANGED
|
@@ -14,6 +14,7 @@ const socket = require('./utility/socket');
|
|
|
14
14
|
const connections = require('./controllers/connections');
|
|
15
15
|
const serverConnections = require('./controllers/serverConnections');
|
|
16
16
|
const databaseConnections = require('./controllers/databaseConnections');
|
|
17
|
+
const restConnections = require('./controllers/restConnections');
|
|
17
18
|
const metadata = require('./controllers/metadata');
|
|
18
19
|
const sessions = require('./controllers/sessions');
|
|
19
20
|
const runners = require('./controllers/runners');
|
|
@@ -267,6 +268,7 @@ function useAllControllers(app, electron) {
|
|
|
267
268
|
useController(app, electron, '/auth', auth);
|
|
268
269
|
useController(app, electron, '/cloud', cloud);
|
|
269
270
|
useController(app, electron, '/team-files', teamFiles);
|
|
271
|
+
useController(app, electron, '/rest-connections', restConnections);
|
|
270
272
|
}
|
|
271
273
|
|
|
272
274
|
function setElectronSender(electronSender) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const childProcessChecker = require('../utility/childProcessChecker');
|
|
2
2
|
const requireEngineDriver = require('../utility/requireEngineDriver');
|
|
3
|
-
const { connectUtility } = require('../utility/connectUtility');
|
|
3
|
+
const { connectUtility, getRestAuthFromConnection } = require('../utility/connectUtility');
|
|
4
4
|
const { handleProcessCommunication } = require('../utility/processComm');
|
|
5
5
|
const { pickSafeConnectionInfo } = require('../utility/crypting');
|
|
6
6
|
const _ = require('lodash');
|
|
@@ -29,6 +29,9 @@ function start() {
|
|
|
29
29
|
try {
|
|
30
30
|
const driver = requireEngineDriver(connection);
|
|
31
31
|
const connectionChanged = driver?.beforeConnectionSave ? driver.beforeConnectionSave(connection) : connection;
|
|
32
|
+
if (driver?.databaseEngineTypes?.includes('rest')) {
|
|
33
|
+
connectionChanged.restAuth = getRestAuthFromConnection(connection);
|
|
34
|
+
}
|
|
32
35
|
|
|
33
36
|
if (!connection.isVolatileResolved) {
|
|
34
37
|
if (connectionChanged.useRedirectDbLogin) {
|
package/src/proc/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const connectProcess = require('./connectProcess');
|
|
2
2
|
const databaseConnectionProcess = require('./databaseConnectionProcess');
|
|
3
3
|
const serverConnectionProcess = require('./serverConnectionProcess');
|
|
4
|
+
const restConnectionProcess = require('./restConnectionProcess');
|
|
4
5
|
const sessionProcess = require('./sessionProcess');
|
|
5
6
|
const jslDatastoreProcess = require('./jslDatastoreProcess');
|
|
6
7
|
const sshForwardProcess = require('./sshForwardProcess');
|
|
@@ -9,6 +10,7 @@ module.exports = {
|
|
|
9
10
|
connectProcess,
|
|
10
11
|
databaseConnectionProcess,
|
|
11
12
|
serverConnectionProcess,
|
|
13
|
+
restConnectionProcess,
|
|
12
14
|
sessionProcess,
|
|
13
15
|
jslDatastoreProcess,
|
|
14
16
|
sshForwardProcess,
|