Skip to content

Instantly share code, notes, and snippets.

@adrianlzt
Created April 16, 2024 09:08
Show Gist options
  • Save adrianlzt/9ef4a1d1c966494ba596c3a1886aaebc to your computer and use it in GitHub Desktop.
Save adrianlzt/9ef4a1d1c966494ba596c3a1886aaebc to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Aplicación para editar un KV secret version 2 en Vault
#
path=$1
tmpfile=$(mktemp)
# Fetch the secret and write it to a temporary file
vault kv get -format=json $path | jq -er .data.data > $tmpfile
# Print error if last command failed
if [ $? -ne 0 ]; then
echo "Error fetching secret from Vault. See $tmpfile for details."
exit 1
fi
# Open the temporary file in your favorite editor
nvim -c 'set filetype=json' $tmpfile
# Validate the JSON syntax
jq -e . $tmpfile > /dev/null
if [ $? -ne 0 ]; then
echo "Invalid JSON syntax. See $tmpfile for details."
exit 1
fi
# Write the modified secret back to Vault
vault kv put $path @$tmpfile
# Remove the temporary file
rm $tmpfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment