@@ -2,18 +2,76 @@ export DEIS_TEST_DOMAIN="xip.io"
22export DO_TOKEN
33export DO_SSH_FINGERPRINT
44
5- prompt " What Digital Ocean token should I use?" DO_TOKEN
6- prompt " What Digital Ocean ssh fingerprint should I use?" DO_SSH_FINGERPRINT
5+ function check-do-token {
6+ if [ ! -z ${1} ]; then
7+ local token=" ${1} "
8+ curl --fail -X GET -H " Authorization: Bearer ${token} " \
9+ " https://api.digitalocean.com/v2/account" & > /dev/null
10+ else
11+ return 1
12+ fi
13+ }
14+
15+ function check-do-ssh-key {
16+ local token=" ${1} "
17+ local ssh_fingerprint=" ${2} "
18+
19+ if [ ! -z ${ssh_fingerprint} ]; then
20+ curl --fail \
21+ -X GET \
22+ -H \
23+ " Authorization: Bearer ${token} " \
24+ " https://api.digitalocean.com/v2/account/keys/${ssh_fingerprint} " & > /dev/null
25+ else
26+ return 1
27+ fi
28+ }
29+
30+ while true ; do
31+ password-prompt " What DigitalOcean token should I use?" DO_TOKEN
32+
33+ if ! check-do-token " ${DO_TOKEN:- } " ; then
34+ rerun_log error " Couldn't login to DigitalOcean using this API token. :-("
35+ unset DO_TOKEN
36+ else
37+ rerun_log info " Successfully logged into DigitalOcean!"
38+ break
39+ fi
40+ done
41+
42+ while true ; do
43+ ssh-private-key-prompt " What private SSH key should I use when creating DigitalOcean droplets?" SSH_PRIVATE_KEY_FILE
44+
45+ export DO_SSH_FINGERPRINT=" $( ssh-fingerprint " ${SSH_PRIVATE_KEY_FILE} " ) "
46+
47+ if ! check-do-ssh-key " ${DO_TOKEN} " " ${DO_SSH_FINGERPRINT:- } " ; then
48+ rerun_log error " Couldn't find the fingerprint for this key in DigitalOcean."
49+
50+ cat << EOF
51+ Upload the public key by pressing the "Add SSH Key" button on
52+ your DigitalOcean security page:
53+
54+ https://cloud.digitalocean.com/settings/security
55+
56+ Or pick a different key...
57+
58+ EOF
59+
60+ unset SSH_PRIVATE_KEY_FILE
61+ else
62+ rerun_log info " This SSH key is correctly configured for use with DigitalOcean!"
63+ break
64+ fi
65+ done
66+
67+ rigger-log " DO_SSH_FINGERPRINT set to ${DO_SSH_FINGERPRINT} "
768
869export TF_VAR_deis_root=" ${DEIS_ROOT} "
9- export TF_VAR_token=" ${DO_TOKEN} "
1070export TF_VAR_ssh_keys=" ${DO_SSH_FINGERPRINT} "
1171export TF_VAR_prefix=" deis-${DEIS_ID} "
1272
1373rigger-save-vars DEIS_TEST_DOMAIN \
14- DO_TOKEN \
1574 DO_SSH_FINGERPRINT \
1675 TF_VAR_deis_root \
1776 TF_VAR_prefix \
18- TF_VAR_ssh_keys \
19- TF_VAR_token
77+ TF_VAR_ssh_keys
0 commit comments