dbmodel - allow connection from env variables

This commit is contained in:
Jan Prochazka
2024-10-01 11:07:12 +02:00
parent ab28a06bef
commit ef5e30df3d
2 changed files with 13 additions and 1 deletions

View File

@@ -3,9 +3,10 @@ const { decryptConnection } = require('./crypting');
const { getSshTunnelProxy } = require('./sshTunnelProxy');
const platformInfo = require('../utility/platformInfo');
const connections = require('../controllers/connections');
const _ = require('lodash');
async function loadConnection(driver, storedConnection, connectionMode) {
const { allowShellConnection } = platformInfo;
const { allowShellConnection, allowConnectionFromEnvVariables } = platformInfo;
if (connectionMode == 'app') {
return storedConnection;
@@ -33,6 +34,16 @@ async function loadConnection(driver, storedConnection, connectionMode) {
}
return loadedWithDb;
}
if (allowConnectionFromEnvVariables) {
return _.mapValues(storedConnection, (value, key) => {
if (_.isString(value) && value.startsWith('$')) {
return process.env[value.substring(1)];
}
return value;
});
}
return storedConnection;
}

View File

@@ -44,6 +44,7 @@ const platformInfo = {
(!processArgs.listenApiChild && !isNpmDist) || !!process.env.SHELL_CONNECTION || !!isElectron() || !!isDbModel,
allowShellScripting:
(!processArgs.listenApiChild && !isNpmDist) || !!process.env.SHELL_SCRIPTING || !!isElectron() || !!isDbModel,
allowConnectionFromEnvVariables: !!isDbModel,
defaultKeyfile: path.join(os.homedir(), '.ssh/id_rsa'),
};