dbgate-api 5.5.5 → 5.5.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dbgate-api",
3
3
  "main": "src/index.js",
4
- "version": "5.5.5",
4
+ "version": "5.5.6",
5
5
  "homepage": "https://dbgate.org/",
6
6
  "repository": {
7
7
  "type": "git",
@@ -27,10 +27,10 @@
27
27
  "compare-versions": "^3.6.0",
28
28
  "cors": "^2.8.5",
29
29
  "cross-env": "^6.0.3",
30
- "dbgate-datalib": "^5.5.5",
30
+ "dbgate-datalib": "^5.5.6",
31
31
  "dbgate-query-splitter": "^4.11.2",
32
- "dbgate-sqltree": "^5.5.5",
33
- "dbgate-tools": "^5.5.5",
32
+ "dbgate-sqltree": "^5.5.6",
33
+ "dbgate-tools": "^5.5.6",
34
34
  "debug": "^4.3.4",
35
35
  "diff": "^5.0.0",
36
36
  "diff2html": "^3.4.13",
@@ -77,7 +77,7 @@
77
77
  "devDependencies": {
78
78
  "@types/fs-extra": "^9.0.11",
79
79
  "@types/lodash": "^4.14.149",
80
- "dbgate-types": "^5.5.5",
80
+ "dbgate-types": "^5.5.6",
81
81
  "env-cmd": "^10.1.0",
82
82
  "node-loader": "^1.0.2",
83
83
  "nodemon": "^2.0.2",
@@ -22,7 +22,8 @@ function unauthorizedResponse(req, res, text) {
22
22
  // if (req.path == getExpressPath('/connections/list')) {
23
23
  // return res.json([]);
24
24
  // }
25
- return res.sendStatus(401).send(text);
25
+
26
+ return res.status(401).send(text);
26
27
  }
27
28
 
28
29
  function authMiddleware(req, res, next) {
@@ -17,6 +17,7 @@ const { checkLicense, checkLicenseKey } = require('../utility/checkLicense');
17
17
  const storage = require('./storage');
18
18
  const { getAuthProxyUrl } = require('../utility/authProxy');
19
19
  const { getPublicHardwareFingerprint } = require('../utility/hardwareFingerprint');
20
+ const { extractErrorMessage } = require('dbgate-tools');
20
21
 
21
22
  const lock = new AsyncLock();
22
23
 
@@ -39,10 +40,12 @@ module.exports = {
39
40
  const isUserLoggedIn = authProvider.isUserLoggedIn(req);
40
41
 
41
42
  const singleConid = authProvider.getSingleConnectionId(req);
43
+ const storageConnectionError = storage.getStorageConnectionError();
42
44
 
43
- const singleConnection = singleConid
44
- ? await connections.getCore({ conid: singleConid })
45
- : connections.singleConnection;
45
+ const singleConnection =
46
+ singleConid && !storageConnectionError
47
+ ? await connections.getCore({ conid: singleConid })
48
+ : connections.singleConnection;
46
49
 
47
50
  let configurationError = null;
48
51
  if (process.env.STORAGE_DATABASE && process.env.BASIC_AUTH) {
@@ -50,8 +53,13 @@ module.exports = {
50
53
  'Basic authentization is not allowed, when using storage. Cannot use both STORAGE_DATABASE and BASIC_AUTH';
51
54
  }
52
55
 
53
- const checkedLicense = await checkLicense();
56
+ if (storageConnectionError && !configurationError) {
57
+ configurationError = extractErrorMessage(storageConnectionError);
58
+ }
59
+
60
+ const checkedLicense = storageConnectionError ? null : await checkLicense();
54
61
  const isLicenseValid = checkedLicense?.status == 'ok';
62
+ const logoutUrl = storageConnectionError ? null : await authProvider.getLogoutUrl();
55
63
 
56
64
  return {
57
65
  runAsPortal: !!connections.portalConnections,
@@ -68,7 +76,7 @@ module.exports = {
68
76
  trialDaysLeft: checkedLicense?.isGeneratedTrial && !checkedLicense?.isExpired ? checkedLicense?.daysLeft : null,
69
77
  checkedLicense,
70
78
  configurationError,
71
- logoutUrl: await authProvider.getLogoutUrl(),
79
+ logoutUrl,
72
80
  permissions,
73
81
  login,
74
82
  // ...additionalConfigProps,
@@ -17,4 +17,8 @@ module.exports = {
17
17
  async getConnectionsForLoginPage() {
18
18
  return null;
19
19
  },
20
+
21
+ getStorageConnectionError() {
22
+ return null;
23
+ }
20
24
  };
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '5.5.5',
4
- buildTime: '2024-10-11T08:23:34.200Z'
3
+ version: '5.5.6',
4
+ buildTime: '2024-10-17T11:26:28.099Z'
5
5
  };
package/src/index.js CHANGED
@@ -4,11 +4,13 @@ const fs = require('fs');
4
4
  const moment = require('moment');
5
5
  const path = require('path');
6
6
  const { logsdir, setLogsFilePath, getLogsFilePath } = require('./utility/directories');
7
+ const currentVersion = require('./currentVersion');
7
8
 
8
9
  const logger = getLogger('apiIndex');
9
10
 
10
11
  process.on('uncaughtException', err => {
11
- logger.fatal(extractErrorLogData(err), 'Uncaught exception');
12
+ logger.fatal(extractErrorLogData(err), 'Uncaught exception, exiting process');
13
+ process.exit(1);
12
14
  });
13
15
 
14
16
  if (processArgs.startProcess) {
@@ -99,10 +101,17 @@ function configureLogger() {
99
101
 
100
102
  if (processArgs.listenApi) {
101
103
  configureLogger();
104
+ logger.info(`Starting API process version ${currentVersion.version}`);
105
+
106
+ if (process.env.DEBUG_PRINT_ENV_VARIABLES) {
107
+ logger.info('Debug print environment variables:');
108
+ for (const key of Object.keys(process.env)) {
109
+ logger.info(` ${key}: ${JSON.stringify(process.env[key])}`);
110
+ }
111
+ }
102
112
  }
103
113
 
104
114
  const shell = require('./shell/index');
105
- const currentVersion = require('./currentVersion');
106
115
 
107
116
  global.DBGATE_PACKAGES = {
108
117
  'dbgate-tools': require('dbgate-tools'),
@@ -20,9 +20,10 @@ function start() {
20
20
  if (handleProcessCommunication(connection)) return;
21
21
  try {
22
22
  const driver = requireEngineDriver(connection);
23
- const conn = await connectUtility(driver, connection, 'app');
24
- const res = await driver.getVersion(conn);
23
+ const dbhan = await connectUtility(driver, connection, 'app');
24
+ const res = await driver.getVersion(dbhan);
25
25
  process.send({ msgtype: 'connected', ...res });
26
+ await driver.close(dbhan);
26
27
  } catch (e) {
27
28
  console.error(e);
28
29
  process.send({
@@ -329,8 +329,9 @@ async function handleSqlPreview({ msgid, objects, options }) {
329
329
  await generator.dump();
330
330
  process.send({ msgtype: 'response', msgid, sql: dmp.s, isTruncated: generator.isTruncated });
331
331
  if (generator.isUnhandledException) {
332
- setTimeout(() => {
332
+ setTimeout(async () => {
333
333
  logger.error('Exiting because of unhandled exception');
334
+ await driver.close(dbhan);
334
335
  process.exit(0);
335
336
  }, 500);
336
337
  }
@@ -406,10 +407,12 @@ async function handleMessage({ msgtype, ...other }) {
406
407
  function start() {
407
408
  childProcessChecker();
408
409
 
409
- setInterval(() => {
410
+ setInterval(async () => {
410
411
  const time = new Date().getTime();
411
412
  if (time - lastPing > 40 * 1000) {
412
413
  logger.info('Database connection not alive, exiting');
414
+ const driver = requireEngineDriver(storedConnection);
415
+ await driver.close(dbhan);
413
416
  process.exit(0);
414
417
  }
415
418
  }, 10 * 1000);
@@ -6,7 +6,7 @@ const connectUtility = require('../utility/connectUtility');
6
6
  const { handleProcessCommunication } = require('../utility/processComm');
7
7
  const logger = getLogger('srvconnProcess');
8
8
 
9
- let systemConnection;
9
+ let dbhan;
10
10
  let storedConnection;
11
11
  let lastDatabases = null;
12
12
  let lastStatus = null;
@@ -16,7 +16,7 @@ let afterConnectCallbacks = [];
16
16
  async function handleRefresh() {
17
17
  const driver = requireEngineDriver(storedConnection);
18
18
  try {
19
- let databases = await driver.listDatabases(systemConnection);
19
+ let databases = await driver.listDatabases(dbhan);
20
20
  if (storedConnection?.allowedDatabases?.trim()) {
21
21
  const allowedDatabaseList = storedConnection.allowedDatabases
22
22
  .split('\n')
@@ -46,7 +46,7 @@ async function handleRefresh() {
46
46
 
47
47
  async function readVersion() {
48
48
  const driver = requireEngineDriver(storedConnection);
49
- const version = await driver.getVersion(systemConnection);
49
+ const version = await driver.getVersion(dbhan);
50
50
  process.send({ msgtype: 'version', version });
51
51
  }
52
52
 
@@ -70,7 +70,7 @@ async function handleConnect(connection) {
70
70
 
71
71
  const driver = requireEngineDriver(storedConnection);
72
72
  try {
73
- systemConnection = await connectUtility(driver, storedConnection, 'app');
73
+ dbhan = await connectUtility(driver, storedConnection, 'app');
74
74
  readVersion();
75
75
  handleRefresh();
76
76
  if (extractBoolSettingsValue(globalSettings, 'connection.autoRefresh', false)) {
@@ -95,7 +95,7 @@ async function handleConnect(connection) {
95
95
  }
96
96
 
97
97
  function waitConnected() {
98
- if (systemConnection) return Promise.resolve();
98
+ if (dbhan) return Promise.resolve();
99
99
  return new Promise((resolve, reject) => {
100
100
  afterConnectCallbacks.push([resolve, reject]);
101
101
  });
@@ -108,14 +108,14 @@ function handlePing() {
108
108
  async function handleDatabaseOp(op, { msgid, name }) {
109
109
  try {
110
110
  const driver = requireEngineDriver(storedConnection);
111
- systemConnection = await connectUtility(driver, storedConnection, 'app');
111
+ dbhan = await connectUtility(driver, storedConnection, 'app');
112
112
  if (driver[op]) {
113
- await driver[op](systemConnection, name);
113
+ await driver[op](dbhan, name);
114
114
  } else {
115
115
  const dmp = driver.createDumper();
116
116
  dmp[op](name);
117
117
  logger.info({ sql: dmp.s }, 'Running script');
118
- await driver.query(systemConnection, dmp.s, { discardResult: true });
118
+ await driver.query(dbhan, dmp.s, { discardResult: true });
119
119
  }
120
120
  await handleRefresh();
121
121
 
@@ -137,11 +137,11 @@ async function handleDriverDataCore(msgid, callMethod) {
137
137
  }
138
138
 
139
139
  async function handleServerSummary({ msgid }) {
140
- return handleDriverDataCore(msgid, driver => driver.serverSummary(systemConnection));
140
+ return handleDriverDataCore(msgid, driver => driver.serverSummary(dbhan));
141
141
  }
142
142
 
143
143
  async function handleSummaryCommand({ msgid, command, row }) {
144
- return handleDriverDataCore(msgid, driver => driver.summaryCommand(systemConnection, command, row));
144
+ return handleDriverDataCore(msgid, driver => driver.summaryCommand(dbhan, command, row));
145
145
  }
146
146
 
147
147
  const messageHandlers = {
@@ -161,10 +161,13 @@ async function handleMessage({ msgtype, ...other }) {
161
161
  function start() {
162
162
  childProcessChecker();
163
163
 
164
- setInterval(() => {
164
+ setInterval(async () => {
165
165
  const time = new Date().getTime();
166
166
  if (time - lastPing > 40 * 1000) {
167
+
167
168
  logger.info('Server connection not alive, exiting');
169
+ const driver = requireEngineDriver(storedConnection);
170
+ await driver.close(dbhan);
168
171
  process.exit(0);
169
172
  }
170
173
  }, 10 * 1000);
@@ -14,7 +14,7 @@ const { getLogger, extractIntSettingsValue, extractBoolSettingsValue } = require
14
14
 
15
15
  const logger = getLogger('sessionProcess');
16
16
 
17
- let systemConnection;
17
+ let dbhan;
18
18
  let storedConnection;
19
19
  let afterConnectCallbacks = [];
20
20
  // let currentHandlers = [];
@@ -177,7 +177,7 @@ function handleStream(driver, resultIndexHolder, sqlItem) {
177
177
  return new Promise((resolve, reject) => {
178
178
  const start = sqlItem.trimStart || sqlItem.start;
179
179
  const handler = new StreamHandler(resultIndexHolder, resolve, start && start.line);
180
- driver.stream(systemConnection, sqlItem.text, handler);
180
+ driver.stream(dbhan, sqlItem.text, handler);
181
181
  });
182
182
  }
183
183
 
@@ -196,7 +196,7 @@ async function handleConnect(connection) {
196
196
  storedConnection = connection;
197
197
 
198
198
  const driver = requireEngineDriver(storedConnection);
199
- systemConnection = await connectUtility(driver, storedConnection, 'app');
199
+ dbhan = await connectUtility(driver, storedConnection, 'app');
200
200
  for (const [resolve] of afterConnectCallbacks) {
201
201
  resolve();
202
202
  }
@@ -210,7 +210,7 @@ async function handleConnect(connection) {
210
210
  // }
211
211
 
212
212
  function waitConnected() {
213
- if (systemConnection) return Promise.resolve();
213
+ if (dbhan) return Promise.resolve();
214
214
  return new Promise((resolve, reject) => {
215
215
  afterConnectCallbacks.push([resolve, reject]);
216
216
  });
@@ -230,7 +230,7 @@ async function handleStartProfiler({ jslid }) {
230
230
  const writer = new TableWriter();
231
231
  writer.initializeFromReader(jslid);
232
232
 
233
- currentProfiler = await driver.startProfiler(systemConnection, {
233
+ currentProfiler = await driver.startProfiler(dbhan, {
234
234
  row: data => writer.rowFromReader(data),
235
235
  });
236
236
  currentProfiler.writer = writer;
@@ -241,7 +241,7 @@ async function handleStopProfiler({ jslid }) {
241
241
 
242
242
  const driver = requireEngineDriver(storedConnection);
243
243
  currentProfiler.writer.close();
244
- driver.stopProfiler(systemConnection, currentProfiler);
244
+ driver.stopProfiler(dbhan, currentProfiler);
245
245
  currentProfiler = null;
246
246
  }
247
247
 
@@ -304,7 +304,7 @@ async function handleExecuteReader({ jslid, sql, fileName }) {
304
304
  const writer = new TableWriter();
305
305
  writer.initializeFromReader(jslid);
306
306
 
307
- const reader = await driver.readQuery(systemConnection, sql);
307
+ const reader = await driver.readQuery(dbhan, sql);
308
308
 
309
309
  reader.on('data', data => {
310
310
  writer.rowFromReader(data);
@@ -340,10 +340,12 @@ function start() {
340
340
 
341
341
  lastPing = new Date().getTime();
342
342
 
343
- setInterval(() => {
343
+ setInterval(async () => {
344
344
  const time = new Date().getTime();
345
345
  if (time - lastPing > 25 * 1000) {
346
346
  logger.info('Session not alive, exiting');
347
+ const driver = requireEngineDriver(storedConnection);
348
+ await driver.close(dbhan);
347
349
  process.exit(0);
348
350
  }
349
351
 
@@ -362,6 +364,8 @@ function start() {
362
364
  executingScripts == 0
363
365
  ) {
364
366
  logger.info('Session not active, exiting');
367
+ const driver = requireEngineDriver(storedConnection);
368
+ await driver.close(dbhan);
365
369
  process.exit(0);
366
370
  }
367
371
  }, 10 * 1000);