Skip to content

Instantly share code, notes, and snippets.

@mrsimonemms
Created January 19, 2021 15:40
Show Gist options
  • Save mrsimonemms/c3d1d219c5f50aa663d91ebd69a59929 to your computer and use it in GitHub Desktop.
Save mrsimonemms/c3d1d219c5f50aa663d91ebd69a59929 to your computer and use it in GitHub Desktop.
Getting OpenFaaS secrets
const { promises: fs } = require('fs');
/**
* Get Secret
*
* Get a secret
*
* @link https://docs.openfaas.com/reference/secrets/#use-the-secret-in-your-function
* @param {string} secretName
* @returns {Promise<string>}
*/
async function getSecret(secretName) {
try {
return await fs.readFile(`/var/openfaas/secrets/${secretName}`, 'utf8');
} catch (err) {
/* Legacy/Docker Compose location */
return fs.readFile(`/run/secrets/${secretName}`, 'utf8');
}
}
import { promises as fs } from 'fs';
/**
* Get Secret
*
* Get a secret
*
* @link https://docs.openfaas.com/reference/secrets/#use-the-secret-in-your-function
* @param {string} secretName
* @returns {Promise<string>}
*/
async function getSecret(secretName) {
try {
return await fs.readFile(`/var/openfaas/secrets/${secretName}`, 'utf8');
} catch {
/* Legacy/Docker Compose location */
return fs.readFile(`/run/secrets/${secretName}`, 'utf8');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment