A DevOps engineer is using Vault Agent templates to render a database password from a KV v2 secrets engine. The secret is stored at secret/data/db with a key named password. The engineer wants to ensure the rendered file contains only the password value and no extra whitespace or newlines. Which template function should be used to trim whitespace from the secret value?
The trim function removes leading and trailing whitespace from a string. Applying it to the secret value ensures the rendered file contains only the password characters, with no stray spaces or newlines. This is the correct choice when the goal is to strip whitespace from the beginning and end of the value while preserving the core content.
Why this answer
Vault Agent templates support the trim function to remove leading and trailing whitespace from a string. Applying it to the retrieved secret value ensures the output file contains only the password. Other functions like toUpper, base64Decode, and regexReplaceAll serve different purposes and do not provide the straightforward whitespace removal needed here.
Exam trap
The trap here is reaching for a more complex function like regexReplaceAll when a simple trim already does the job.