Skip to content

Commit

Permalink
Merge pull request #4192 from skyksandr/master
Browse files Browse the repository at this point in the history
Vultr Api: Update to v2
  • Loading branch information
Neilpang authored Jul 19, 2022
2 parents 3e628f2 + 0717f85 commit de04192
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions dnsapi/dns_vultr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#
#VULTR_API_KEY=000011112222333344445555666677778888

VULTR_Api="https://api.vultr.com/v1"
VULTR_Api="https://api.vultr.com/v2"

######## Public functions #####################

#
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_vultr_add() {
fulldomain=$1
Expand All @@ -31,14 +31,14 @@ dns_vultr_add() {
_debug _domain "$_domain"

_debug 'Getting txt records'
_vultr_rest GET "dns/records?domain=$_domain"
_vultr_rest GET "domains/$_domain/records"

if printf "%s\n" "$response" | grep -- "\"type\":\"TXT\",\"name\":\"$fulldomain\"" >/dev/null; then
_err 'Error'
return 1
fi

if ! _vultr_rest POST 'dns/create_record' "domain=$_domain&name=$_sub_domain&data=\"$txtvalue\"&type=TXT"; then
if ! _vultr_rest POST "domains/$_domain/records" "{\"name\":\"$_sub_domain\",\"data\":\"$txtvalue\",\"type\":\"TXT\"}"; then
_err "$response"
return 1
fi
Expand Down Expand Up @@ -71,14 +71,14 @@ dns_vultr_rm() {
_debug _domain "$_domain"

_debug 'Getting txt records'
_vultr_rest GET "dns/records?domain=$_domain"
_vultr_rest GET "domains/$_domain/records"

if printf "%s\n" "$response" | grep -- "\"type\":\"TXT\",\"name\":\"$fulldomain\"" >/dev/null; then
_err 'Error'
return 1
fi

_record_id="$(echo "$response" | tr '{}' '\n' | grep '"TXT"' | grep -- "$txtvalue" | tr ',' '\n' | grep -i 'RECORDID' | cut -d : -f 2)"
_record_id="$(echo "$response" | tr '{}' '\n' | grep '"TXT"' | grep -- "$txtvalue" | tr ',' '\n' | grep -i 'id' | cut -d : -f 2)"
_debug _record_id "$_record_id"
if [ "$_record_id" ]; then
_info "Successfully retrieved the record id for ACME challenge."
Expand All @@ -87,7 +87,7 @@ dns_vultr_rm() {
return 0
fi

if ! _vultr_rest POST 'dns/delete_record' "domain=$_domain&RECORDID=$_record_id"; then
if ! _vultr_rest DELETE "domains/$_domain/records/$_record_id"; then
_err "$response"
return 1
fi
Expand All @@ -112,11 +112,11 @@ _get_root() {
return 1
fi

if ! _vultr_rest GET "dns/list"; then
if ! _vultr_rest GET "domains"; then
return 1
fi

if printf "%s\n" "$response" | grep '^\[.*\]' >/dev/null; then
if printf "%s\n" "$response" | grep '^\{.*\}' >/dev/null; then
if _contains "$response" "\"domain\":\"$_domain\""; then
_sub_domain="$(echo "$fulldomain" | sed "s/\\.$_domain\$//")"
return 0
Expand All @@ -141,8 +141,8 @@ _vultr_rest() {

api_key_trimmed=$(echo $VULTR_API_KEY | tr -d '"')

export _H1="Api-Key: $api_key_trimmed"
export _H2='Content-Type: application/x-www-form-urlencoded'
export _H1="Authorization: Bearer $api_key_trimmed"
export _H2='Content-Type: application/json'

if [ "$m" != "GET" ]; then
_debug data "$data"
Expand Down

0 comments on commit de04192

Please sign in to comment.