Skip to content

Commit

Permalink
Add support to read CA certificate from file
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Kurashov committed Apr 22, 2019
1 parent 2a8af9f commit 3d09817
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ENV ME_CONFIG_EDITORTHEME="default" \
ME_CONFIG_MONGODB_ADMINPASSWORD_FILE="" \
ME_CONFIG_MONGODB_AUTH_USERNAME_FILE="" \
ME_CONFIG_MONGODB_AUTH_PASSWORD_FILE="" \
ME_CONFIG_MONGODB_CA_FILE="" \
VCAP_APP_HOST="0.0.0.0"

WORKDIR /app
Expand Down
32 changes: 31 additions & 1 deletion config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ function getFileEnv(envVariable) {

}

var sslCA = 'ME_CONFIG_MONGODB_CA_FILE';

function getBinaryFileEnv(envVariable) {

var fileVar = process.env[envVariable];

if (typeof fileVar !== 'undefined' && fileVar) {

const fs = require('fs');

const path = fileVar;


try {
if (fs.existsSync(path)) {
//file exists
var varFromFile = fs.readFileSync(path);

return varFromFile;
}
} catch (err) {
console.error(err);
}
} else {

return null;
}

}

var meConfigMongodbServer = process.env.ME_CONFIG_MONGODB_SERVER ? process.env.ME_CONFIG_MONGODB_SERVER.split(',') : false;

module.exports = {
Expand All @@ -70,7 +100,7 @@ module.exports = {
sslValidate: process.env.ME_CONFIG_MONGODB_SSLVALIDATE || true,

//sslCA: array of valid CA certificates
sslCA: [],
sslCA: [getBinaryFileEnv(sslCA)],

//autoReconnect: automatically reconnect if connection is lost
autoReconnect: true,
Expand Down

0 comments on commit 3d09817

Please sign in to comment.