3 EXOSCALE_API
=https
://api.exoscale.com
/dns
/v1
5 ######## Public functions #####################
7 # Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
8 # Used to add txt record
17 _debug
"First detect the root zone"
18 if ! _get_root
"$fulldomain"; then
23 _debug _sub_domain
"$_sub_domain"
24 _debug _domain
"$_domain"
27 if _exoscale_rest POST
"domains/$_domain_id/records" "{\"record\":{\"name\":\"$_sub_domain\",\"record_type\":\"TXT\",\"content\":\"$txtvalue\",\"ttl\":120}}" "$_domain_token"; then
28 if _contains
"$response" "$txtvalue"; then
33 _err
"Add txt record error."
38 # Usage: fulldomain txtvalue
39 # Used to remove the txt record after validation
48 _debug
"First detect the root zone"
49 if ! _get_root
"$fulldomain"; then
54 _debug _sub_domain
"$_sub_domain"
55 _debug _domain
"$_domain"
57 _debug
"Getting txt records"
58 _exoscale_rest GET
"domains/${_domain_id}/records?type=TXT&name=$_sub_domain" "" "$_domain_token"
59 if _contains
"$response" "\"name\":\"$_sub_domain\"" >/dev
/null
; then
60 _record_id
=$
(echo "$response" |
tr '{' "\n" |
grep "\"content\":\"$txtvalue\"" | _egrep_o
"\"id\":[^,]+" | _head_n
1 | cut
-d : -f 2 |
tr -d \")
63 if [ -z "$_record_id" ]; then
64 _err
"Can not get record id to remove."
68 _debug
"Deleting record $_record_id"
70 if ! _exoscale_rest DELETE
"domains/$_domain_id/records/$_record_id" "" "$_domain_token"; then
71 _err
"Delete record error."
78 #################### Private functions below ##################################
81 EXOSCALE_API_KEY
="${EXOSCALE_API_KEY:-$(_readaccountconf_mutable EXOSCALE_API_KEY)}"
82 EXOSCALE_SECRET_KEY
="${EXOSCALE_SECRET_KEY:-$(_readaccountconf_mutable EXOSCALE_SECRET_KEY)}"
84 if [ -z "$EXOSCALE_API_KEY" ] ||
[ -z "$EXOSCALE_SECRET_KEY" ]; then
86 EXOSCALE_SECRET_KEY
=""
87 _err
"You don't specify Exoscale application key and application secret yet."
88 _err
"Please create you key and try again."
92 _saveaccountconf_mutable EXOSCALE_API_KEY
"$EXOSCALE_API_KEY"
93 _saveaccountconf_mutable EXOSCALE_SECRET_KEY
"$EXOSCALE_SECRET_KEY"
98 #_acme-challenge.www.domain.com
100 # _sub_domain=_acme-challenge.www
102 # _domain_id=sdjkglgdfewsdfg
103 # _domain_token=sdjkglgdfewsdfg
106 if ! _exoscale_rest GET
"domains"; then
114 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
121 if _contains
"$response" "\"name\":\"$h\"" >/dev
/null
; then
122 _domain_id
=$
(echo "$response" |
tr '{' "\n" |
grep "\"name\":\"$h\"" | _egrep_o
"\"id\":[^,]+" | _head_n
1 | cut
-d : -f 2 |
tr -d \")
123 _domain_token
=$
(echo "$response" |
tr '{' "\n" |
grep "\"name\":\"$h\"" | _egrep_o
"\"token\":\"[^\"]*\"" | _head_n
1 | cut
-d : -f 2 |
tr -d \")
124 if [ "$_domain_token" ] && [ "$_domain_id" ]; then
125 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
143 request_url
="$EXOSCALE_API/$path"
146 export _H1
="Accept: application/json"
148 if [ "$token" ]; then
149 export _H2
="X-DNS-Domain-Token: $token"
151 export _H2
="X-DNS-Token: $EXOSCALE_API_KEY:$EXOSCALE_SECRET_KEY"
154 if [ "$data" ] ||
[ "$method" = "DELETE" ]; then
155 export _H3
="Content-Type: application/json"
157 response
="$(_post "$data" "$request_url" "" "$method")"
159 response
="$(_get "$request_url" "" "" "$method")"
162 if [ "$?" != "0" ]; then
163 _err
"error $request_url"
166 _debug2 response
"$response"