mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 03:16:01 +00:00
SYNC: private cloud UX + fixes
This commit is contained in:
committed by
Diflow
parent
f2af38da4c
commit
d668128a34
@@ -4,6 +4,7 @@ const { getSshTunnelProxy } = require('./sshTunnelProxy');
|
||||
const platformInfo = require('../utility/platformInfo');
|
||||
const connections = require('../controllers/connections');
|
||||
const _ = require('lodash');
|
||||
const { getCloudFolderEncryptor } = require('./cloudIntf');
|
||||
|
||||
async function loadConnection(driver, storedConnection, connectionMode) {
|
||||
const { allowShellConnection, allowConnectionFromEnvVariables } = platformInfo;
|
||||
@@ -88,13 +89,31 @@ async function extractConnectionSslParams(connection) {
|
||||
return ssl;
|
||||
}
|
||||
|
||||
async function decryptCloudConnection(connection) {
|
||||
const m = connection?._id?.match(/^cloud\:\/\/(.+)\/(.+)$/);
|
||||
if (!m) {
|
||||
throw new Error('Invalid cloud connection ID format');
|
||||
}
|
||||
|
||||
const folid = m[1];
|
||||
const cntid = m[2];
|
||||
|
||||
const folderEncryptor = await getCloudFolderEncryptor(folid);
|
||||
return decryptConnection(connection, folderEncryptor);
|
||||
}
|
||||
|
||||
async function connectUtility(driver, storedConnection, connectionMode, additionalOptions = null) {
|
||||
const connectionLoaded = await loadConnection(driver, storedConnection, connectionMode);
|
||||
|
||||
const connection = {
|
||||
database: connectionLoaded.defaultDatabase,
|
||||
...decryptConnection(connectionLoaded),
|
||||
};
|
||||
const connection = connectionLoaded?._id?.startsWith('cloud://')
|
||||
? {
|
||||
database: connectionLoaded.defaultDatabase,
|
||||
...(await decryptCloudConnection(connectionLoaded)),
|
||||
}
|
||||
: {
|
||||
database: connectionLoaded.defaultDatabase,
|
||||
...decryptConnection(connectionLoaded),
|
||||
};
|
||||
|
||||
if (!connection.port && driver.defaultPort) {
|
||||
connection.port = driver.defaultPort.toString();
|
||||
|
||||
@@ -91,11 +91,11 @@ function encryptObjectPasswordField(obj, field, encryptor = null) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
function decryptObjectPasswordField(obj, field) {
|
||||
function decryptObjectPasswordField(obj, field, encryptor = null) {
|
||||
if (obj && obj[field] && obj[field].startsWith('crypt:')) {
|
||||
return {
|
||||
...obj,
|
||||
[field]: getInternalEncryptor().decrypt(obj[field].substring('crypt:'.length)),
|
||||
[field]: (encryptor || getInternalEncryptor()).decrypt(obj[field].substring('crypt:'.length)),
|
||||
};
|
||||
}
|
||||
return obj;
|
||||
@@ -115,10 +115,10 @@ function maskConnection(connection) {
|
||||
return _.omit(connection, ['password', 'sshPassword', 'sshKeyfilePassword']);
|
||||
}
|
||||
|
||||
function decryptConnection(connection) {
|
||||
connection = decryptObjectPasswordField(connection, 'password');
|
||||
connection = decryptObjectPasswordField(connection, 'sshPassword');
|
||||
connection = decryptObjectPasswordField(connection, 'sshKeyfilePassword');
|
||||
function decryptConnection(connection, encryptor = null) {
|
||||
connection = decryptObjectPasswordField(connection, 'password', encryptor);
|
||||
connection = decryptObjectPasswordField(connection, 'sshPassword', encryptor);
|
||||
connection = decryptObjectPasswordField(connection, 'sshKeyfilePassword', encryptor);
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user