-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig.sh
More file actions
executable file
·77 lines (61 loc) · 1.99 KB
/
config.sh
File metadata and controls
executable file
·77 lines (61 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
export DEIS_TEST_DOMAIN="xip.io"
export DO_TOKEN
export DO_SSH_FINGERPRINT
function check-do-token {
if [ ! -z ${1} ]; then
local token="${1}"
curl --fail -X GET -H "Authorization: Bearer ${token}" \
"https://api.digitalocean.com/v2/account" &> /dev/null
else
return 1
fi
}
function check-do-ssh-key {
local token="${1}"
local ssh_fingerprint="${2}"
if [ ! -z ${ssh_fingerprint} ]; then
curl --fail \
-X GET \
-H \
"Authorization: Bearer ${token}" \
"https://api.digitalocean.com/v2/account/keys/${ssh_fingerprint}" &> /dev/null
else
return 1
fi
}
while true; do
password-prompt "What DigitalOcean token should I use?" DO_TOKEN
if ! check-do-token "${DO_TOKEN:-}"; then
rerun_log error "Couldn't login to DigitalOcean using this API token. :-("
unset DO_TOKEN
else
rerun_log info "Successfully logged into DigitalOcean!"
break
fi
done
while true; do
ssh-private-key-prompt "What private SSH key should I use when creating DigitalOcean droplets?" SSH_PRIVATE_KEY_FILE
export DO_SSH_FINGERPRINT="$(ssh-fingerprint "${SSH_PRIVATE_KEY_FILE}")"
if ! check-do-ssh-key "${DO_TOKEN}" "${DO_SSH_FINGERPRINT:-}"; then
rerun_log error "Couldn't find the fingerprint for this key in DigitalOcean."
cat <<EOF
Upload the public key by pressing the "Add SSH Key" button on
your DigitalOcean security page:
https://cloud.digitalocean.com/settings/security
Or pick a different key...
EOF
unset SSH_PRIVATE_KEY_FILE
else
rerun_log info "This SSH key is correctly configured for use with DigitalOcean!"
break
fi
done
rigger-log "DO_SSH_FINGERPRINT set to ${DO_SSH_FINGERPRINT}"
export TF_VAR_deis_root="${DEIS_ROOT}"
export TF_VAR_ssh_keys="${DO_SSH_FINGERPRINT}"
export TF_VAR_prefix="deis-${DEIS_ID}"
rigger-save-vars DEIS_TEST_DOMAIN \
DO_SSH_FINGERPRINT \
TF_VAR_deis_root \
TF_VAR_prefix \
TF_VAR_ssh_keys