Skip to content

Commit 9bd278a

Browse files
authored
feat(deployment): encrypt heroku auth token in bash (#134)
1 parent 8f51518 commit 9bd278a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"build-client": "webpack",
1111
"build-client-watch": "webpack -w",
1212
"deploy": "script/deploy",
13+
"heroku-token": "script/encrypt-heroku-auth-token",
1314
"lint": "eslint ./ --ignore-path .gitignore",
1415
"lint-fix": "npm run lint -- --fix",
1516
"precommit": "# lint-staged # un-comment to enable",

script/encrypt-heroku-auth-token

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
function cleanup_at_exit {
6+
# remove temporary key file
7+
rm tmp.pem
8+
}
9+
10+
trap cleanup_at_exit EXIT
11+
12+
# Get the repo name from the `origin` git remote.
13+
export REPO=$(git remote get-url origin | \
14+
sed 's/^.*[\/:]\([^\/:]*\)\/\([^\/]*\)$/\1\/\2/' | \
15+
sed 's/^\(.*\)\.git$/\1/'
16+
)
17+
18+
# Get the Travis public key for this repo.
19+
export TRAVIS_KEY=$(curl --silent https://api.travis-ci.org/repos/$REPO/key)
20+
21+
# Save the key to a file.
22+
node -e "console.log($TRAVIS_KEY['key'])" > tmp.pem
23+
24+
# Generate a Heroku token, encrypt and encode it and print it in YAML.
25+
echo -n $(heroku auth:token) | \
26+
openssl rsautl -encrypt -pubin -inkey tmp.pem | \
27+
base64 | awk '{print " secure: "$1}'

0 commit comments

Comments
 (0)