File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change 11import dotenv from 'dotenv' ;
22
3- export const getEnv = ( env : string | undefined , defaultValue ?: string , required ?: boolean ) => {
4- if ( required && ! env && ! defaultValue ) {
5- throw new Error ( `Missing required environment variable` ) ;
6- }
7-
3+ export const getEnv = ( env : string | undefined , defaultValue ?: string ) => {
84 return env ?? defaultValue ;
95}
106
@@ -14,4 +10,4 @@ dotenv.config({
1410} ) ;
1511
1612// @note : You can use https://generate-random.org/encryption-key-generator to create a new 32 byte key
17- export const SOURCEBOT_ENCRYPTION_KEY = getEnv ( process . env . SOURCEBOT_ENCRYPTION_KEY , undefined , true ) ! ;
13+ export const SOURCEBOT_ENCRYPTION_KEY = getEnv ( process . env . SOURCEBOT_ENCRYPTION_KEY ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ const generateIV = (): Buffer => {
99} ;
1010
1111export function encrypt ( text : string ) : { iv : string ; encryptedData : string } {
12+ if ( ! SOURCEBOT_ENCRYPTION_KEY ) {
13+ throw new Error ( 'Encryption key is not set' ) ;
14+ }
15+
1216 const encryptionKey = Buffer . from ( SOURCEBOT_ENCRYPTION_KEY , 'ascii' ) ;
1317
1418 const iv = generateIV ( ) ;
@@ -21,6 +25,10 @@ export function encrypt(text: string): { iv: string; encryptedData: string } {
2125}
2226
2327export function decrypt ( iv : string , encryptedText : string ) : string {
28+ if ( ! SOURCEBOT_ENCRYPTION_KEY ) {
29+ throw new Error ( 'Encryption key is not set' ) ;
30+ }
31+
2432 const encryptionKey = Buffer . from ( SOURCEBOT_ENCRYPTION_KEY , 'ascii' ) ;
2533
2634 const ivBuffer = Buffer . from ( iv , 'hex' ) ;
You can’t perform that action at this time.
0 commit comments