fixed test connection for electron + better logging

This commit is contained in:
Jan Prochazka
2021-12-30 09:57:24 +01:00
parent 15de3600c3
commit 88469e7366
5 changed files with 37 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ const crypto = require('crypto');
const simpleEncryptor = require('simple-encryptor');
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const { datadir } = require('./directories');
@@ -81,8 +82,18 @@ function decryptConnection(connection) {
return connection;
}
function pickSafeConnectionInfo(connection) {
return _.mapValues(connection, (v, k) => {
if (k == 'engine' || k == 'port' || k == 'authType' || k == 'sshMode' || k == 'passwordMode') return v;
if (v === null || v === true || v === false) return v;
if (v) return '***';
return undefined;
});
}
module.exports = {
loadEncryptionKey,
encryptConnection,
decryptConnection,
pickSafeConnectionInfo,
};

View File

@@ -1,5 +1,6 @@
const _ = require('lodash');
const requirePlugin = require('../shell/requirePlugin');
const { pickSafeConnectionInfo } = require('./crypting');
/** @returns {import('dbgate-types').EngineDriver} */
function requireEngineDriver(connection) {
@@ -10,14 +11,14 @@ function requireEngineDriver(connection) {
engine = connection.engine;
}
if (!engine) {
throw new Error('Could not get driver from connection');
throw new Error(`Could not get driver from connection ${JSON.stringify(pickSafeConnectionInfo(connection))}`);
}
if (engine.includes('@')) {
const [shortName, packageName] = engine.split('@');
const plugin = requirePlugin(packageName);
return plugin.drivers.find(x => x.engine == engine);
}
throw new Error(`Could not found engine driver ${engine}`);
throw new Error(`Could not find engine driver ${engine}`);
}
module.exports = requireEngineDriver;