Last active
May 9, 2021 07:46
-
-
Save javatarz/8775d0d2a9ad124eefff9df6b2d431eb to your computer and use it in GitHub Desktop.
Encrypts files with openssl
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 | |
set -e | |
if [ -z "$SECRET_KEY" ]; then | |
echo "Set a SECRET_KEY for \"$WORKSPACE_NAME\" encryption" | |
exit 1 | |
fi | |
function encrypt_file() { | |
input_file=$1 | |
target_file="$input_file.enc" | |
echo "Encrypting $input_file to $target_file" | |
openssl enc -aes-256-cbc -salt -in $input_file -out $target_file -pass pass:$SECRET_KEY | |
rm -f $input_file | |
} | |
if [ -z $1 ]; then | |
echo "Usage:" | |
echo " ./scripts/encrypt.sh <filePathFromProjectRoot>" | |
echo " ./scripts/encrypt.sh all" | |
exit 2 | |
elif [ "$1" == "all" ]; then | |
for input_file in config/$WORKSPACE_NAME/*.tfsecrets; do | |
encrypt_file $input_file | |
done | |
else | |
encrypt_file $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment