github.com/naphatkrit/deis@v1.12.3/contrib/digitalocean/config.sh (about) 1 export DEIS_TEST_DOMAIN="xip.io" 2 export DO_TOKEN 3 export DO_SSH_FINGERPRINT 4 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}" 68 69 export TF_VAR_deis_root="${DEIS_ROOT}" 70 export TF_VAR_ssh_keys="${DO_SSH_FINGERPRINT}" 71 export TF_VAR_prefix="deis-${DEIS_ID}" 72 73 rigger-save-vars DEIS_TEST_DOMAIN \ 74 DO_SSH_FINGERPRINT \ 75 TF_VAR_deis_root \ 76 TF_VAR_prefix \ 77 TF_VAR_ssh_keys