8 RACKSPACE_Endpoint
="https://dns.api.rackspacecloud.com/v1.0"
10 # 20210923 - RS changed the fields in the API response; fix sed
11 # 20190213 - The name & id fields swapped in the API response; fix sed
12 # 20190101 - Duplicating file for new pull request to dev branch
13 # Original - tcocca:rackspace_dnsapi https://github.com/acmesh-official/acme.sh/pull/1297
15 ######## Public functions #####################
16 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
19 _debug fulldomain
="$fulldomain"
21 _debug txtvalue
="$txtvalue"
22 _rackspace_check_auth ||
return 1
23 _rackspace_check_rootzone ||
return 1
24 _info
"Creating TXT record."
25 if ! _rackspace_rest POST
"$RACKSPACE_Tenant/domains/$_domain_id/records" "{\"records\":[{\"name\":\"$fulldomain\",\"type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":300}]}"; then
28 _debug2 response
"$response"
29 if ! _contains
"$response" "$txtvalue" >/dev
/null
; then
30 _err
"Could not add TXT record."
39 _debug fulldomain
="$fulldomain"
41 _debug txtvalue
="$txtvalue"
42 _rackspace_check_auth ||
return 1
43 _rackspace_check_rootzone ||
return 1
44 _info
"Checking for TXT record."
45 if ! _get_recordid
"$_domain_id" "$fulldomain" "$txtvalue"; then
46 _err
"Could not get TXT record id."
49 if [ "$_dns_record_id" = "" ]; then
50 _err
"TXT record not found."
53 _info
"Removing TXT record."
54 if ! _delete_txt_record
"$_domain_id" "$_dns_record_id"; then
55 _err
"Could not remove TXT record $_dns_record_id."
60 #################### Private functions below ##################################
61 #_acme-challenge.www.domain.com
63 # _sub_domain=_acme-challenge.www
65 # _domain_id=sdjkglgdfewsdfg
71 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
77 if ! _rackspace_rest GET
"$RACKSPACE_Tenant/domains/search?name=$h"; then
80 _debug2 response
"$response"
81 if _contains
"$response" "\"name\":\"$h\"" >/dev
/null
; then
82 # Response looks like:
83 # {"id":"12345","accountId":"1111111","name": "example.com","ttl":3600,"emailAddress": ... <and so on>
84 _domain_id
=$
(echo "$response" |
sed -n "s/^.*\"id\":\"\([^,]*\)\",\"accountId\":\"[0-9]*\",\"name\":\"$h\",.*/\1/p")
85 _debug2 domain_id
"$_domain_id"
86 if [ -n "$_domain_id" ]; then
87 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
103 if ! _rackspace_rest GET
"$RACKSPACE_Tenant/domains/$domainid/records?name=$fulldomain&type=TXT"; then
106 _debug response
"$response"
107 if ! _contains
"$response" "$txtvalue"; then
111 _dns_record_id
=$
(echo "$response" |
tr '{' "\n" |
grep "\"data\":\"$txtvalue\"" |
sed -n 's/^.*"id":"\([^"]*\)".*/\1/p')
112 _debug _dns_record_id
"$_dns_record_id"
116 _delete_txt_record
() {
119 if ! _rackspace_rest DELETE
"$RACKSPACE_Tenant/domains/$domainid/records?id=$_dns_record_id"; then
122 _debug response
"$response"
123 if ! _contains
"$response" "RUNNING"; then
134 export _H1
="Accept: application/json"
135 export _H2
="X-Auth-Token: $RACKSPACE_Token"
136 export _H3
="X-Project-Id: $RACKSPACE_Tenant"
137 export _H4
="Content-Type: application/json"
138 if [ "$m" != "GET" ]; then
140 response
="$(_post "$data" "$RACKSPACE_Endpoint/$ep" "" "$m")"
143 _info
"Getting $RACKSPACE_Endpoint/$ep"
144 response
="$(_get "$RACKSPACE_Endpoint/$ep")"
148 if [ "$retcode" != "0" ]; then
152 _debug2 response
"$response"
156 _rackspace_authorization
() {
157 export _H1
="Content-Type: application/json"
158 data
="{\"auth\":{\"RAX-KSKEY:apiKeyCredentials\":{\"username\":\"$RACKSPACE_Username\",\"apiKey\":\"$RACKSPACE_Apikey\"}}}"
160 response
="$(_post "$data" "https
://identity.api.rackspacecloud.com
/v2.0
/tokens
" "" "POST
")"
162 _debug2 response
"$response"
163 if [ "$retcode" != "0" ]; then
164 _err
"Authentication failed."
167 if _contains
"$response" "token"; then
168 RACKSPACE_Token
="$(echo "$response" | _normalizeJson | sed -n 's/^.*"token
":{.*,"id
":"\
([^
"]*\)",".*/\1/p')"
169 RACKSPACE_Tenant
="$(echo "$response" | _normalizeJson | sed -n 's/^.*"token
":{.*,"id
":"\
([^
"]*\)"}.
*/\
1/p
')"
170 _debug RACKSPACE_Token "$RACKSPACE_Token"
171 _debug RACKSPACE_Tenant "$RACKSPACE_Tenant"
176 _rackspace_check_auth() {
177 # retrieve the rackspace creds
178 RACKSPACE_Username="${RACKSPACE_Username:-$(_readaccountconf_mutable RACKSPACE_Username)}"
179 RACKSPACE_Apikey="${RACKSPACE_Apikey:-$(_readaccountconf_mutable RACKSPACE_Apikey)}"
180 # check their vals for null
181 if [ -z "$RACKSPACE_Username" ] || [ -z "$RACKSPACE_Apikey" ]; then
182 RACKSPACE_Username=""
184 _err "You didn't specify a Rackspace username and api key.
"
185 _err "Please
set those values and try again.
"
188 # save the username and api key to the account conf file.
189 _saveaccountconf_mutable RACKSPACE_Username "$RACKSPACE_Username"
190 _saveaccountconf_mutable RACKSPACE_Apikey "$RACKSPACE_Apikey"
191 if [ -z "$RACKSPACE_Token" ]; then
192 _info "Getting authorization token.
"
193 if ! _rackspace_authorization; then
194 _err "Can not get token.
"
199 _rackspace_check_rootzone() {
200 _debug "First detect the root zone
"
201 if ! _get_root_zone "$fulldomain"; then
202 _err "invalid domain
"
205 _debug _domain_id "$_domain_id"
206 _debug _sub_domain "$_sub_domain"
207 _debug _domain "$_domain"