dbgate-api-premium 6.0.0 → 6.1.1

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-premium",
3
3
  "main": "src/index.js",
4
- "version": "6.0.0",
4
+ "version": "6.1.1",
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.0.0",
32
+ "dbgate-datalib": "^6.1.1",
33
33
  "dbgate-query-splitter": "^4.11.2",
34
- "dbgate-sqltree": "^6.0.0",
35
- "dbgate-tools": "^6.0.0",
34
+ "dbgate-sqltree": "^6.1.1",
35
+ "dbgate-tools": "^6.1.1",
36
36
  "debug": "^4.3.4",
37
37
  "diff": "^5.0.0",
38
38
  "diff2html": "^3.4.13",
@@ -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.0.0",
84
+ "dbgate-types": "^6.1.1",
85
85
  "env-cmd": "^10.1.0",
86
86
  "jsdoc-to-markdown": "^9.0.5",
87
87
  "node-loader": "^1.0.2",
@@ -230,7 +230,7 @@ class LoginsProvider extends AuthProviderBase {
230
230
  ),
231
231
  };
232
232
  }
233
-
233
+
234
234
  return { error: 'Invalid credentials' };
235
235
  }
236
236
 
@@ -271,11 +271,10 @@ function hasEnvLogins() {
271
271
  return false;
272
272
  }
273
273
 
274
- function detectEnvAuthProvider() {
274
+ function detectEnvAuthProviderCore() {
275
275
  if (process.env.AUTH_PROVIDER) {
276
276
  return process.env.AUTH_PROVIDER;
277
277
  }
278
-
279
278
  if (process.env.STORAGE_DATABASE) {
280
279
  return 'denyall';
281
280
  }
@@ -291,6 +290,14 @@ function detectEnvAuthProvider() {
291
290
  return 'none';
292
291
  }
293
292
 
293
+ function detectEnvAuthProvider() {
294
+ const authProvider = detectEnvAuthProviderCore();
295
+ if (process.env.BASIC_AUTH && authProvider != 'logins' && authProvider != 'ad') {
296
+ throw new Error(`BASIC_AUTH is not supported with ${authProvider} auth provider`);
297
+ }
298
+ return authProvider;
299
+ }
300
+
294
301
  function createEnvAuthProvider() {
295
302
  const authProvider = detectEnvAuthProvider();
296
303
  switch (authProvider) {
@@ -9,6 +9,7 @@ const _ = require('lodash');
9
9
  const AsyncLock = require('async-lock');
10
10
  const jwt = require('jsonwebtoken');
11
11
 
12
+ const processArgs = require('../utility/processArgs');
12
13
  const currentVersion = require('../currentVersion');
13
14
  const platformInfo = require('../utility/platformInfo');
14
15
  const connections = require('../controllers/connections');
@@ -83,7 +84,8 @@ module.exports = {
83
84
  isElectron: platformInfo.isElectron,
84
85
  isLicenseValid,
85
86
  isLicenseExpired: checkedLicense?.isExpired,
86
- trialDaysLeft: checkedLicense?.licenseTypeObj?.isTrial && !checkedLicense?.isExpired ? checkedLicense?.daysLeft : null,
87
+ trialDaysLeft:
88
+ checkedLicense?.licenseTypeObj?.isTrial && !checkedLicense?.isExpired ? checkedLicense?.daysLeft : null,
87
89
  checkedLicense,
88
90
  configurationError,
89
91
  logoutUrl,
@@ -101,7 +103,10 @@ module.exports = {
101
103
  adminPasswordState: adminConfig?.adminPasswordState,
102
104
  storageDatabase: process.env.STORAGE_DATABASE,
103
105
  logsFilePath: getLogsFilePath(),
104
- connectionsFilePath: path.join(datadir(), 'connections.jsonl'),
106
+ connectionsFilePath: path.join(
107
+ datadir(),
108
+ processArgs.runE2eTests ? 'connections-e2etests.jsonl' : 'connections.jsonl'
109
+ ),
105
110
  ...currentVersion,
106
111
  };
107
112
 
@@ -199,7 +199,9 @@ module.exports = {
199
199
  const dir = datadir();
200
200
  if (!portalConnections) {
201
201
  // @ts-ignore
202
- this.datastore = new JsonLinesDatabase(path.join(dir, 'connections.jsonl'));
202
+ this.datastore = new JsonLinesDatabase(
203
+ path.join(dir, processArgs.runE2eTests ? 'connections-e2etests.jsonl' : 'connections.jsonl')
204
+ );
203
205
  }
204
206
  await this.checkUnsavedConnectionsLimit();
205
207
  },
@@ -220,7 +222,7 @@ module.exports = {
220
222
  },
221
223
 
222
224
  test_meta: true,
223
- test(connection) {
225
+ test({ connection, requestDbList }) {
224
226
  const subprocess = fork(
225
227
  global['API_PACKAGE'] || process.argv[1],
226
228
  [
@@ -235,7 +237,7 @@ module.exports = {
235
237
  }
236
238
  );
237
239
  pipeForkLogs(subprocess);
238
- subprocess.send(connection);
240
+ subprocess.send({ connection, requestDbList });
239
241
  return new Promise(resolve => {
240
242
  subprocess.on('message', resp => {
241
243
  if (handleProcessCommunication(resp, subprocess)) return;
@@ -510,4 +512,10 @@ module.exports = {
510
512
  }
511
513
  return null;
512
514
  },
515
+
516
+ reloadConnectionList_meta: true,
517
+ async reloadConnectionList() {
518
+ if (portalConnections) return;
519
+ await this.datastore.unload();
520
+ },
513
521
  };
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '6.0.0',
4
- buildTime: '2024-12-05T11:13:06.142Z'
3
+ version: '6.1.1',
4
+ buildTime: '2024-12-23T06:08:08.745Z'
5
5
  };
package/src/main.js CHANGED
@@ -28,6 +28,7 @@ const files = require('./controllers/files');
28
28
  const scheduler = require('./controllers/scheduler');
29
29
  const queryHistory = require('./controllers/queryHistory');
30
30
  const onFinished = require('on-finished');
31
+ const processArgs = require('./utility/processArgs');
31
32
 
32
33
  const { rundir } = require('./utility/directories');
33
34
  const platformInfo = require('./utility/platformInfo');
@@ -77,6 +78,8 @@ function start() {
77
78
  app.use(getExpressPath('/'), express.static('/home/dbgate-docker/public'));
78
79
  } else if (platformInfo.isAwsUbuntuLayout) {
79
80
  app.use(getExpressPath('/'), express.static('/home/ubuntu/build/public'));
81
+ } else if (processArgs.runE2eTests) {
82
+ app.use(getExpressPath('/'), express.static(path.resolve('packer/build/public')));
80
83
  } else if (platformInfo.isNpmDist) {
81
84
  app.use(
82
85
  getExpressPath('/'),
@@ -16,13 +16,19 @@ Platform: ${process.platform}
16
16
 
17
17
  function start() {
18
18
  childProcessChecker();
19
- process.on('message', async connection => {
19
+ process.on('message', async args => {
20
+ // @ts-ignore
21
+ const { connection, requestDbList } = args;
20
22
  if (handleProcessCommunication(connection)) return;
21
23
  try {
22
24
  const driver = requireEngineDriver(connection);
23
25
  const dbhan = await connectUtility(driver, connection, 'app');
24
26
  const res = await driver.getVersion(dbhan);
25
- process.send({ msgtype: 'connected', ...res });
27
+ let databases = undefined;
28
+ if (requestDbList) {
29
+ databases = await driver.listDatabases(dbhan);
30
+ }
31
+ process.send({ msgtype: 'connected', ...res, databases });
26
32
  await driver.close(dbhan);
27
33
  } catch (e) {
28
34
  console.error(e);
@@ -8,12 +8,15 @@ const logger = getLogger('tableReader');
8
8
  * @param {object} options
9
9
  * @param {connectionType} options.connection - connection object
10
10
  * @param {object} options.systemConnection - system connection (result of driver.connect). If not provided, new connection will be created
11
+ * @param {object} options.driver - driver object. If not provided, it will be loaded from connection
11
12
  * @param {string} options.pureName - table name
12
13
  * @param {string} options.schemaName - schema name
13
14
  * @returns {Promise<readerType>} - reader object
14
15
  */
15
- async function tableReader({ connection, systemConnection, pureName, schemaName }) {
16
- const driver = requireEngineDriver(connection);
16
+ async function tableReader({ connection, systemConnection, pureName, schemaName, driver }) {
17
+ if (!driver) {
18
+ driver = requireEngineDriver(connection);
19
+ }
17
20
  const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
18
21
  logger.info(`Connected.`);
19
22
 
@@ -23,6 +23,12 @@ class JsonLinesDatabase {
23
23
  await fs.writeFile(this.filename, this.data.map(x => JSON.stringify(x)).join('\n'));
24
24
  }
25
25
 
26
+ async unload() {
27
+ this.data = [];
28
+ this.loadedOk = false;
29
+ this.loadPerformed = false;
30
+ }
31
+
26
32
  async _ensureLoaded() {
27
33
  if (!this.loadPerformed) {
28
34
  await lock.acquire('reader', async () => {
@@ -96,6 +96,9 @@ function packagedPluginsDir() {
96
96
  // return path.resolve(__dirname, '../../plugins');
97
97
  // }
98
98
  }
99
+ if (processArgs.runE2eTests) {
100
+ return path.resolve('packer/build/plugins');
101
+ }
99
102
  return null;
100
103
  }
101
104
 
@@ -14,6 +14,7 @@ const workspaceDir = getNamedArg('--workspace-dir');
14
14
  const processDisplayName = getNamedArg('--process-display-name');
15
15
  const listenApi = process.argv.includes('--listen-api');
16
16
  const listenApiChild = process.argv.includes('--listen-api-child') || listenApi;
17
+ const runE2eTests = process.argv.includes('--run-e2e-tests');
17
18
 
18
19
  function getPassArgs() {
19
20
  const res = [];
@@ -23,6 +24,9 @@ function getPassArgs() {
23
24
  if (listenApiChild) {
24
25
  res.push('listen-api-child');
25
26
  }
27
+ if (runE2eTests) {
28
+ res.push('--run-e2e-tests');
29
+ }
26
30
  return res;
27
31
  }
28
32
 
@@ -36,4 +40,5 @@ module.exports = {
36
40
  listenApi,
37
41
  listenApiChild,
38
42
  processDisplayName,
43
+ runE2eTests,
39
44
  };