Skip to content

Commit

Permalink
Merge pull request #4794 from zbbfufu/feature/gandi-replace-apikey-by…
Browse files Browse the repository at this point in the history
…-personal-token

dns_gandi: implements token in addition to the (deprecated) API key
  • Loading branch information
Neilpang authored Sep 13, 2023
2 parents 86521ec + 558e706 commit 1a90f66
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions dnsapi/dns_gandi_livedns.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env sh

# Gandi LiveDNS v5 API
# https://doc.livedns.gandi.net/
# https://api.gandi.net/docs/livedns/
# https://api.gandi.net/docs/authentication/ for token + apikey (deprecated) authentication
# currently under beta
#
# Requires GANDI API KEY set in GANDI_LIVEDNS_KEY set as environment variable
Expand All @@ -19,13 +20,20 @@ dns_gandi_livedns_add() {
fulldomain=$1
txtvalue=$2

if [ -z "$GANDI_LIVEDNS_KEY" ]; then
_err "No API key specified for Gandi LiveDNS."
_err "Create your key and export it as GANDI_LIVEDNS_KEY"
if [ -z "$GANDI_LIVEDNS_KEY" ] && [ -z "$GANDI_LIVEDNS_TOKEN" ]; then
_err "No Token or API key (deprecated) specified for Gandi LiveDNS."
_err "Create your token or key and export it as GANDI_LIVEDNS_KEY or GANDI_LIVEDNS_TOKEN respectively"
return 1
fi

_saveaccountconf GANDI_LIVEDNS_KEY "$GANDI_LIVEDNS_KEY"
# Keep only one secret in configuration
if [ -n "$GANDI_LIVEDNS_TOKEN" ]; then
_saveaccountconf GANDI_LIVEDNS_TOKEN "$GANDI_LIVEDNS_TOKEN"
_clearaccountconf GANDI_LIVEDNS_KEY
elif [ -n "$GANDI_LIVEDNS_KEY" ]; then
_saveaccountconf GANDI_LIVEDNS_KEY "$GANDI_LIVEDNS_KEY"
_clearaccountconf GANDI_LIVEDNS_TOKEN
fi

_debug "First detect the root zone"
if ! _get_root "$fulldomain"; then
Expand Down Expand Up @@ -157,7 +165,12 @@ _gandi_livedns_rest() {
_debug "$ep"

export _H1="Content-Type: application/json"
export _H2="X-Api-Key: $GANDI_LIVEDNS_KEY"

if [ -n "$GANDI_LIVEDNS_TOKEN" ]; then
export _H2="Authorization: Bearer $GANDI_LIVEDNS_TOKEN"
else
export _H2="X-Api-Key: $GANDI_LIVEDNS_KEY"
fi

if [ "$m" = "GET" ]; then
response="$(_get "$GANDI_LIVEDNS_API/$ep")"
Expand Down

0 comments on commit 1a90f66

Please sign in to comment.