Skip to content

Instantly share code, notes, and snippets.

@jayhding
Created August 30, 2018 03:33
Show Gist options
  • Save jayhding/74d6e2adfbe7eb312732ff2d492ca659 to your computer and use it in GitHub Desktop.
Save jayhding/74d6e2adfbe7eb312732ff2d492ca659 to your computer and use it in GitHub Desktop.
This script is used to rename a path in vault by listing all credentials then add to new path
#!/usr/bin/env bash
old_path=$1
new_path=$2
raw_list=$(vault list ${old_path})
list=$(echo "${raw_list}" | sed -e "s/Keys//" -e "s/----//" -e "/^\s*$/d")
IFS=$'\n'; list_array=($list);
for item in "${list_array[@]}"; do
raw_value=$(vault read ${old_path}/${item})
value=$(echo "${raw_value}" | grep "value" | awk '{print $2}')
echo "Prepare write to ${new_path}/${item}"
vault write "${new_path}/${item}" value="${value}"
echo "Delete old key"
vault delete "${old_path}/${item}"
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment