Skip to content

Commit

Permalink
Remove region, use NodeJS instead of Python to pick apart the JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico Huijbers committed May 31, 2018
1 parent be15422 commit c79b719
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sign.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ if [[ "${2:-}" == "" ]]; then
exit 1
fi


tmpdir=$(mktemp -d)
trap "shred $tmpdir/* && rm -rf $tmpdir" EXIT

SECRET=CDK/$1/SigningKey

This comment has been minimized.

Copy link
@eladb

eladb May 31, 2018

Contributor

Assign "$1" to a variable to improve readability


# Use secrets manager to obtain the key and passphrase into a JSON file
echo "Retrieving key $SECRET..." >&2
aws --region us-east-1 secretsmanager get-secret-value --secret-id "$SECRET" --output text --query SecretString > $tmpdir/secret.txt
passphrase=$(python -c "import json; print(json.load(file('$tmpdir/secret.txt'))['Passphrase'])")
aws secretsmanager get-secret-value --secret-id "$SECRET" --output text --query SecretString > $tmpdir/secret.txt

value-from-secret() {
node -e "console.log(JSON.parse(require('fs').readFileSync('$tmpdir/secret.txt', { encoding: 'utf-8' })).$1)"

This comment has been minimized.

Copy link
@eladb

eladb May 31, 2018

Contributor

Assign "$1" to some local variable to improve readability

This comment has been minimized.

Copy link
@eladb

eladb May 31, 2018

Contributor

I don't think you need to require("fs"). Node implicitly requires all the SDK modules when you use -e

}

passphrase=$(value-from-secret Passphrase)

echo "Importing key..." >&2
gpg --homedir $tmpdir --import <(python -c "import json; print(json.load(file('$tmpdir/secret.txt'))['PrivateKey'])")
gpg --homedir $tmpdir --import <(value-from-secret PrivateKey)

while [[ "${2:-}" != "" ]]; do
echo "Signing $2..." >&2
Expand Down

1 comment on commit c79b719

@eladb
Copy link
Contributor

@eladb eladb commented on c79b719 May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to get Stephen to take a quick look?

Please sign in to comment.