Class SecretUtil
java.lang.Object
com.github.cafapi.common.util.secret.SecretUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Retrieves a secret value from various sources based on configuration: Environment variables (if CAF_ENABLE_ENV_SECRETS is true or not set) File content (if CAF_ENABLE_FILE_SECRETS is true and path specified by environment variable with "_FILE" suffix) For example, for a key "DATABASE_PASSWORD": First checks environment variable (if enabled): DATABASE_PASSWORD Then checks file path in environment variable (if enabled): DATABASE_PASSWORD_FILEstatic String
Retrieves a secret value from various sources based on configuration: Environment variables (if CAF_ENABLE_ENV_SECRETS is true or not set) File content (if CAF_ENABLE_FILE_SECRETS is true and path specified by environment variable with "_FILE" suffix) For example, for a key "DATABASE_PASSWORD": First checks environment variable (if enabled): DATABASE_PASSWORD Then checks file path in environment variable (if enabled): DATABASE_PASSWORD_FILE
-
Method Details
-
getSecret
Retrieves a secret value from various sources based on configuration:- Environment variables (if CAF_ENABLE_ENV_SECRETS is true or not set)
- File content (if CAF_ENABLE_FILE_SECRETS is true and path specified by environment variable with "_FILE" suffix)
- First checks environment variable (if enabled): DATABASE_PASSWORD
- Then checks file path in environment variable (if enabled): DATABASE_PASSWORD_FILE
- Parameters:
key
- The base key to look up the secret value. Must not be null.- Returns:
- The secret value if found in any of the enabled sources, or null if not found. If found in a file, the content is trimmed of leading and trailing whitespace.
- Throws:
IOException
- If there is an error reading the file when using the _FILE variantNullPointerException
- If the key parameter is null
-
getSecret
Retrieves a secret value from various sources based on configuration:- Environment variables (if CAF_ENABLE_ENV_SECRETS is true or not set)
- File content (if CAF_ENABLE_FILE_SECRETS is true and path specified by environment variable with "_FILE" suffix)
- First checks environment variable (if enabled): DATABASE_PASSWORD
- Then checks file path in environment variable (if enabled): DATABASE_PASSWORD_FILE
- Parameters:
key
- The base key to look up the secret value. Must not be null.defaultValue
- The value to return if no secret is found. May be null.- Returns:
- The secret value if found in any of the enabled sources, or defaultValue if not found. If found in a file, the content is trimmed of leading and trailing whitespace.
- Throws:
IOException
- If there is an error reading the file when using the _FILE variantNullPointerException
- If the key parameter is null
-