Function Signature
Parameters
The environment variable name that points to the secret file path
Array of allowed string values for the enum
Optional default value to return if the secret is not found (must be one of the allowed values)
Returns
Promise<T[number]> - One of the allowed enum values from the secret file
How It Works
This function reads secrets from the filesystem, following Docker secrets conventions:- Checks if the environment variable
keycontains a file path - If no path is set, defaults to
/run/secrets/{key} - Reads the file contents and validates it against the allowed values
- Throws an error if the secret is missing or not in the allowed values (unless a fallback is provided)
Example
Error Handling
Throws an error if:- The secret file doesn’t exist (when no fallback provided)
- The file is empty (when no fallback provided)
- The value is not one of the allowed enum values
