Add ability to read secrets from docker

This commit is contained in:
walcutt 2024-02-27 21:55:40 -05:00
parent 4a23e18d83
commit abe6b2366b
4 changed files with 38 additions and 3 deletions

View File

@ -7,7 +7,15 @@
"": { "": {
"name": "asher-discord-bot", "name": "asher-discord-bot",
"version": "0.0.0", "version": "0.0.0",
"license": "ISC" "license": "ISC",
"dependencies": {
"fs": "^0.0.1-security"
}
},
"node_modules/fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
} }
} }
} }

View File

@ -2,6 +2,7 @@
"name": "asher-discord-bot", "name": "asher-discord-bot",
"version": "0.0.0", "version": "0.0.0",
"description": "best friends bot", "description": "best friends bot",
"type": "module",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
"serve": "node src/index.js", "serve": "node src/index.js",
@ -16,5 +17,8 @@
"bugs": { "bugs": {
"url": "https://github.com/walcutt/asher/issues" "url": "https://github.com/walcutt/asher/issues"
}, },
"homepage": "https://github.com/walcutt/asher#readme" "homepage": "https://github.com/walcutt/asher#readme",
"dependencies": {
"fs": "^0.0.1-security"
}
} }

View File

@ -1 +1,3 @@
console.log("hello world!"); import { secretKeys, getSecret } from "./secrets.js";
console.log(getSecret(secretKeys.BOT_KEY));

21
asher/src/secrets.js Normal file
View File

@ -0,0 +1,21 @@
import fs from 'fs';
export const secretKeys = {
BOT_KEY: 'botkey'
};
const secretManifest = [
secretKeys.BOT_KEY,
];
let secrets = {};
secretManifest.forEach(
(key) => {
secrets[key] = fs.readFileSync(`/run/secrets/${key}`, { encoding: "utf-8" });
}
);
export function getSecret(key) {
return secrets[key];
}