4 # https://developers.scaleway.com/en/products/domain/dns/api/
6 # Requires Scaleway API token set in SCALEWAY_API_TOKEN
8 ######## Public functions #####################
10 SCALEWAY_API
="https://api.scaleway.com/domain/v2beta1"
12 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
17 if ! _scaleway_check_config
; then
21 _debug
"First detect the root zone"
22 if ! _get_root
"$fulldomain"; then
27 _debug _sub_domain
"$_sub_domain"
28 _debug _domain
"$_domain"
31 _scaleway_create_TXT_record
"$_domain" "$_sub_domain" "$txtvalue"
32 if _contains
"$response" "records"; then
35 _err error
"$response"
47 if ! _scaleway_check_config
; then
51 _debug
"First detect the root zone"
52 if ! _get_root
"$fulldomain"; then
57 _debug _sub_domain
"$_sub_domain"
58 _debug _domain
"$_domain"
60 _info
"Deleting record"
61 _scaleway_delete_TXT_record
"$_domain" "$_sub_domain" "$txtvalue"
62 if _contains
"$response" "records"; then
65 _err error
"$response"
68 _info
"Record deleted."
73 #################### Private functions below ##################################
75 _scaleway_check_config
() {
76 SCALEWAY_API_TOKEN
="${SCALEWAY_API_TOKEN:-$(_readaccountconf_mutable SCALEWAY_API_TOKEN)}"
77 if [ -z "$SCALEWAY_API_TOKEN" ]; then
78 _err
"No API key specified for Scaleway API."
79 _err
"Create your key and export it as SCALEWAY_API_TOKEN"
82 if ! _scaleway_rest GET
"dns-zones"; then
83 _err
"Invalid API key specified for Scaleway API."
87 _saveaccountconf_mutable SCALEWAY_API_TOKEN
"$SCALEWAY_API_TOKEN"
92 #_acme-challenge.www.domain.com
94 # _sub_domain=_acme-challenge.www
101 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
107 _scaleway_rest GET
"dns-zones/$h/records"
109 if ! _contains
"$response" "subdomain not found" >/dev
/null
; then
110 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
117 _err
"Unable to retrive DNS zone matching this domain"
121 # this function add a TXT record
122 _scaleway_create_TXT_record
() {
127 _scaleway_rest PATCH
"dns-zones/$txt_zone/records" "{\"return_all_records\":false,\"changes\":[{\"add\":{\"records\":[{\"name\":\"$txt_name\",\"data\":\"$txt_value\",\"type\":\"TXT\",\"ttl\":60}]}}]}"
129 if _contains
"$response" "records"; then
132 _err
"error1 $response"
137 # this function delete a TXT record based on name and content
138 _scaleway_delete_TXT_record
() {
143 _scaleway_rest PATCH
"dns-zones/$txt_zone/records" "{\"return_all_records\":false,\"changes\":[{\"delete\":{\"id_fields\":{\"name\":\"$txt_name\",\"data\":\"$txt_value\",\"type\":\"TXT\"}}}]}"
145 if _contains
"$response" "records"; then
148 _err
"error2 $response"
158 _scaleway_url
="$SCALEWAY_API/$ep"
159 _debug2 _scaleway_url
"$_scaleway_url"
160 export _H1
="x-auth-token: $SCALEWAY_API_TOKEN"
161 export _H2
="Accept: application/json"
162 export _H3
="Content-Type: application/json"
164 if [ "$data" ] ||
[ "$m" != "GET" ]; then
166 response
="$(_post "$data" "$_scaleway_url" "" "$m")"
168 response
="$(_get "$_scaleway_url")"
170 if [ "$?" != "0" ] || _contains
"$response" "denied_authentication" || _contains
"$response" "Method not allowed" || _contains
"$response" "json parse error: unexpected EOF"; then
171 _err
"error $response"
174 _debug2 response
"$response"