Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes key_placer.sh when encrypting files #1465

Merged
merged 4 commits into from
Oct 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions scripts/key_placer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,40 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR
cd ..

if [[ $1 != "encrypt" ]] && [[ $1 != "decrypt" ]]; then
echo "invalid action $1. Choose 'encrypt' or 'decrypt'"
exit 1
fi

command -v gcloud > /dev/null 2>&1

if [[ $? -eq 1 ]]; then
echo "gcloud is not installed - skipping decryption"
echo "gcloud is not installed - skipping ${1}ion"
exit 0
fi

for file_path in "${files[@]}"; do
file_path_without_extension=`echo "$file_path" | sed "s/.*\///"`
file_dir=$(dirname "${file_path}")
encrypted="$file_dir/$file_path_without_extension.enc"
encrypted_file_path="$file_path.enc"

if [[ $1 == "decrypt" ]] && ! test -f "$encrypted_file_path"; then
echo "$encrypted_file_path does not exist, cannot decrypt - skipping file"
continue
elif [[ $1 == "encrypt" ]] && ! test -f "$file_path"; then
echo "$file_path does not exist, cannot encrypt - skipping file"
continue
fi

if test -f "$encrypted"; then
gcloud kms $1 --ciphertext-file=$encrypted --plaintext-file=$file_path --key=github-key --keyring=celo-keyring --location=global --project celo-testnet > /dev/null 2>&1
if [[ $? -eq 1 ]]; then
echo "Only C Labs employees can decrypt keys - skipping decryption"
exit 0
fi
gcloud kms $1 --ciphertext-file=$encrypted_file_path --plaintext-file=$file_path --key=github-key --keyring=celo-keyring --location=global --project celo-testnet
if [[ $? -eq 1 ]]; then
echo "Only C Labs employees can $1 keys - skipping ${1}ion"
exit 0
fi
done

echo "Encrypted files decrypted"
if [[ $1 == "decrypt" ]]; then
echo "Encrypted files decrypted"
elif [[ $1 == "encrypt" ]]; then
echo "Decrypted files encrypted"
fi

exit 0