Export env functions for test and add log

This commit is contained in:
2025-09-12 09:48:47 +02:00
parent f7bf9fe29f
commit 2d6f8f6730
+10 -7
View File
@@ -9,13 +9,16 @@ const FILE_EXT = '__FILE'
// Read from env or file
export async function read_env(key: string): Promise<Ok<string | undefined>> {
const path = process.env[key + FILE_EXT]
if (path !== undefined) return from_file(path)
else return {ok: true, data: process.env[key]}
if (path !== undefined) {
log.debug(`Read ${key} from a file`)
log.trace('Path :', path)
return from_file(path)
} else {
log.debug(`Read ${key} from env`)
return {ok: true, data: process.env[key]}
}
}
async function from_file(path: string): Promise<Ok<string>> {
log.debug('Read a key from a file')
log.trace('Path :', path)
export async function from_file(path: string): Promise<Ok<string>> {
const content = await get_file_content(path)
if (!content.ok) return content
@@ -23,7 +26,7 @@ async function from_file(path: string): Promise<Ok<string>> {
return content
}
async function get_file_content(path: string): Promise<Ok<string>> {
export async function get_file_content(path: string): Promise<Ok<string>> {
log.debug('Read file content')
log.trace('Path :', path)