mirror of
https://github.com/acmesh-official/acme.sh.git
synced 2026-10-21 21:31:51 +00:00
dns_dnsimple: support user tokens (dnsimple_u_*) https://github.com/acmesh-official/acme.sh/issues/6491
This commit is contained in:
1 parent
f4d2db64ef
commit
20254cbaf0
1 file changed
+29
-7
+29
-7
@@ -5,6 +5,7 @@ Site: DNSimple.com
|
|||||||
Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_dnsimple
|
Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_dnsimple
|
||||||
Options:
|
Options:
|
||||||
DNSimple_OAUTH_TOKEN OAuth Token
|
DNSimple_OAUTH_TOKEN OAuth Token
|
||||||
|
DNSimple_ACCOUNT_ID Account ID. Optional, only needed when the token can access multiple accounts.
|
||||||
Issues: github.com/pho3nixf1re/acme.sh/issues
|
Issues: github.com/pho3nixf1re/acme.sh/issues
|
||||||
'
|
'
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ dns_dnsimple_add() {
|
|||||||
_saveaccountconf DNSimple_OAUTH_TOKEN "$DNSimple_OAUTH_TOKEN"
|
_saveaccountconf DNSimple_OAUTH_TOKEN "$DNSimple_OAUTH_TOKEN"
|
||||||
|
|
||||||
if ! _get_account_id; then
|
if ! _get_account_id; then
|
||||||
_err "failed to retrive account id"
|
_err "failed to retrieve account id"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ dns_dnsimple_rm() {
|
|||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
|
|
||||||
if ! _get_account_id; then
|
if ! _get_account_id; then
|
||||||
_err "failed to retrive account id"
|
_err "failed to retrieve account id"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -122,13 +123,16 @@ _get_root() {
|
|||||||
|
|
||||||
# returns _account_id
|
# returns _account_id
|
||||||
_get_account_id() {
|
_get_account_id() {
|
||||||
_debug "retrive account id"
|
DNSimple_ACCOUNT_ID="${DNSimple_ACCOUNT_ID:-$(_readaccountconf DNSimple_ACCOUNT_ID)}"
|
||||||
if ! _dnsimple_rest GET "whoami"; then
|
if [ "$DNSimple_ACCOUNT_ID" ]; then
|
||||||
return 1
|
_saveaccountconf DNSimple_ACCOUNT_ID "$DNSimple_ACCOUNT_ID"
|
||||||
|
_account_id="$DNSimple_ACCOUNT_ID"
|
||||||
|
_debug _account_id "$_account_id"
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if _contains "$response" "\"account\":null"; then
|
_debug "retrieve account id"
|
||||||
_err "no account associated with this token"
|
if ! _dnsimple_rest GET "whoami"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -137,7 +141,25 @@ _get_account_id() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if _contains "$response" "\"account\":null"; then
|
||||||
|
# the whoami of a user token (dnsimple_u_*) carries no account,
|
||||||
|
# so list the accounts the token can access instead
|
||||||
|
# https://github.com/acmesh-official/acme.sh/issues/6491
|
||||||
|
if ! _dnsimple_rest GET "accounts"; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
_account_id=$(printf "%s" "$response" | _egrep_o "\"id\":[^,]*,\"email\":" | cut -d: -f2 | cut -d, -f1)
|
_account_id=$(printf "%s" "$response" | _egrep_o "\"id\":[^,]*,\"email\":" | cut -d: -f2 | cut -d, -f1)
|
||||||
|
if [ -z "$_account_id" ]; then
|
||||||
|
_err "no account associated with this token"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if [ "$(echo "$_account_id" | wc -l)" -gt 1 ]; then
|
||||||
|
_err "The token has access to multiple accounts, please pick one and set it explicitly:"
|
||||||
|
_err "export DNSimple_ACCOUNT_ID=<one of: $(echo "$_account_id" | tr '\n' ' ')>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
_debug _account_id "$_account_id"
|
_debug _account_id "$_account_id"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||