INNER CODE UNIT · JavaScript
main
shortlink-org/shortlink · boundaries/common/script/kube-secret-fetcher/index.js:10
async function main() {
const argv = yargs(hideBin(process.argv)).options({
'namespace': { type: 'string', demandOption: true, describe: 'Kubernetes namespace' },
'secret': { type: 'string', demandOption: true, describe: 'Secret name' },
'key': { type: 'string', demandOption: true, describe: 'Key inside the secret' },
'envKey': { type: 'string', demandOption: true, describe: 'Key for the .env file' },
'envPath': { type: 'string', default: '.env', describe: 'Path to the .env file' }
}).argv;
const { namespace, secret: secretName, key, envKey, envPath } = argv;
try {
const { stdout } = await execPromisified(`kubectl -n ${namespace} get secret ${secretName} -o json`);
const secret = JSON.parse(stdout);
const keyValueBase64 = secret.data[key];
const keyValueDecoded = Buffer.from(keyValueBase64, 'base64').toString().replace('.svc', '');
let envConfig = fs.readFileSync(envPath, 'utf8').split(os.EOL);