Last active
May 9, 2021 07:45
-
-
Save javatarz/5aedf7066b408511975d3cb97ce0ee5a to your computer and use it in GitHub Desktop.
Tests all files for openssl encryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
base_dir="config" | |
for sub_dir in $(find $base_dir -mindepth 1 -maxdepth 1 -type d); do | |
workspace_name=${sub_dir#"$base_dir/"} | |
password_var_name="\$SECRET_KEY_$workspace_name" | |
secret_key_for_workspace=$(eval "echo $password_var_name") | |
if [ -z "$secret_key_for_workspace" ]; then | |
echo "Variable $password_var_name has not been set. Unable to test" | |
exit 1 | |
fi | |
for input_file in config/$workspace_name/*.tfsecrets.enc | |
do | |
openssl enc -aes-256-cbc -d -in $input_file -pass pass:$secret_key_for_workspace &> /dev/null | |
if [ $? != 0 ]; then | |
echo "Unable to decrypt $input_file with $password_var_name" | |
exit 1 | |
fi | |
done | |
echo "Successfully decrypted all secrets in config/$workspace_name" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment