Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Created February 2, 2020 18:40
Show Gist options
  • Save PatrickKalkman/fc8b2c68a28e011f037127056ad095b1 to your computer and use it in GitHub Desktop.
Save PatrickKalkman/fc8b2c68a28e011f037127056ad095b1 to your computer and use it in GitHub Desktop.
Reading secrets from the file system
// dependencies
const fs = require('fs');
const log = require('../log');
const dockerSecret = {};
dockerSecret.read = function read(secretNameAndPath) {
try {
return fs.readFileSync(`${secretNameAndPath}`, 'utf8');
} catch(err) {
if (err.code !== 'ENOENT') {
log.error(`An error occurred while trying to read the secret: ${secretNameAndPath}. Err: ${err}`);
} else {
log.debug(`Could not find the secret, probably not running in swarm mode: ${secretNameAndPath}. Err: ${err}`);
}
return false;
}
};
module.exports = dockerSecret;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment