Function Signature
Parameters
The environment variable name that points to the secret file path
Returns
Promise<string[] | undefined> - An array of strings from the secret file, or undefined if not found
How It Works
This is the optional variant ofsecretStrings. It reads secrets from the filesystem without throwing errors when the file is missing:
- Checks if the environment variable
keycontains a file path - If no path is set, defaults to
/run/secrets/{key} - Reads the file contents and splits by comma
- Trims whitespace from each value and filters out empty strings
- Returns
undefinedif the secret file doesn’t exist (instead of throwing)
Difference from secretStrings
- maybeSecretStrings: Returns
undefinedwhen the secret file is missing - secretStrings: Throws an error when the secret file is missing (unless a fallback is provided)
maybeSecretStrings for truly optional list secrets where absence is a valid state.
Example
Secret File Format
The secret file should contain comma-separated values:Error Handling
Returnsundefined if:
- The secret file doesn’t exist
- The file is empty
