Add ability to read secrets from docker
This commit is contained in:
		
							parent
							
								
									4a23e18d83
								
							
						
					
					
						commit
						abe6b2366b
					
				
							
								
								
									
										10
									
								
								asher/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										10
									
								
								asher/package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -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==" | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -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" | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -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
									
								
							
							
						
						
									
										21
									
								
								asher/src/secrets.js
									
									
									
									
									
										Normal 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]; | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 walcutt
						walcutt