forked from acmesh-official/acme.sh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dnsapi] Support adding / removing multiple TXT values for Gandi
Gandi supports setting multiple entries by setting multiple array items for the rrset_values field in their API. Modify the dns_gandi_livedns.sh script so that it checks for existing entries, appends new ones if needed, and removes existing ones individually. This enabled wildcard certificate support on Gandi. Fixes the dns_gandi_livedns part of acmesh-official#1261. Tested for creating a multidomain, multiple wild-card certificate on Gandi and using a test script executing only the dns_gandi_livedns_add and dns_gandi_livedns_rm functions.
- Loading branch information
Showing
1 changed file
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
# Requires GANDI API KEY set in GANDI_LIVEDNS_KEY set as environment variable | ||
# | ||
#Author: Frédéric Crozat <[email protected]> | ||
# Dominik Röttsches <[email protected]> | ||
#Report Bugs here: https://github.com/fcrozat/acme.sh | ||
# | ||
######## Public functions ##################### | ||
|
@@ -36,9 +37,7 @@ dns_gandi_livedns_add() { | |
_debug domain "$_domain" | ||
_debug sub_domain "$_sub_domain" | ||
|
||
_gandi_livedns_rest PUT "domains/$_domain/records/$_sub_domain/TXT" "{\"rrset_ttl\": 300, \"rrset_values\":[\"$txtvalue\"]}" \ | ||
&& _contains "$response" '{"message": "DNS Record Created"}' \ | ||
&& _info "Add $(__green "success")" | ||
_dns_gandi_append_record "$_domain" "$_sub_domain" "$txtvalue" | ||
} | ||
|
||
#Usage: fulldomain txtvalue | ||
|
@@ -56,9 +55,23 @@ dns_gandi_livedns_rm() { | |
_debug fulldomain "$fulldomain" | ||
_debug domain "$_domain" | ||
_debug sub_domain "$_sub_domain" | ||
_debug txtvalue "$txtvalue" | ||
|
||
_gandi_livedns_rest DELETE "domains/$_domain/records/$_sub_domain/TXT" "" | ||
|
||
if ! _dns_gandi_existing_rrset_values "$_domain" "$_sub_domain"; then | ||
return 1 | ||
fi | ||
_new_rrset_values=$(echo "$_rrset_values" | sed "s/...$txtvalue...//g") | ||
# Cleanup dangling commata. | ||
_new_rrset_values=$(echo "$_new_rrset_values" | sed "s/, ,/ ,/g") | ||
_new_rrset_values=$(echo "$_new_rrset_values" | sed "s/, *\]/\]/g") | ||
_new_rrset_values=$(echo "$_new_rrset_values" | sed "s/\[ *,/\[/g") | ||
_debug "New rrset_values" "$_new_rrset_values" | ||
|
||
_gandi_livedns_rest PUT \ | ||
"domains/$_domain/records/$_sub_domain/TXT" \ | ||
"{\"rrset_ttl\": 300, \"rrset_values\": $_new_rrset_values}" \ | ||
&& _contains "$response" '{"message": "DNS Record Created"}' \ | ||
&& _info "Removing record $(__green "success")" | ||
} | ||
|
||
#################### Private functions below ################################## | ||
|
@@ -98,6 +111,45 @@ _get_root() { | |
return 1 | ||
} | ||
|
||
_dns_gandi_append_record() { | ||
domain=$1 | ||
sub_domain=$2 | ||
txtvalue=$3 | ||
|
||
if _dns_gandi_existing_rrset_values "$domain" "$sub_domain"; then | ||
_debug "Appending new value" | ||
_rrset_values=$(echo "$_rrset_values" | sed "s/\"]/\",\"$txtvalue\"]/") | ||
else | ||
_debug "Creating new record" "$_rrset_values" | ||
_rrset_values="[\"$txtvalue\"]" | ||
fi | ||
_debug new_rrset_values "$_rrset_values" | ||
_gandi_livedns_rest PUT "domains/$_domain/records/$sub_domain/TXT" \ | ||
"{\"rrset_ttl\": 300, \"rrset_values\": $_rrset_values}" \ | ||
&& _contains "$response" '{"message": "DNS Record Created"}' \ | ||
&& _info "Adding record $(__green "success")" | ||
} | ||
|
||
_dns_gandi_existing_rrset_values() { | ||
domain=$1 | ||
sub_domain=$2 | ||
if ! _gandi_livedns_rest GET "domains/$domain/records/$sub_domain"; then | ||
return 1 | ||
fi | ||
if ! _contains "$response" '"rrset_type": "TXT"'; then | ||
_debug "Does not have a _acme-challenge TXT record yet." | ||
return 1 | ||
fi | ||
if _contains "$response" '"rrset_values": \[\]'; then | ||
_debug "Empty rrset_values for TXT record, no previous TXT record." | ||
return 1 | ||
fi | ||
_debug "Already has TXT record." | ||
_rrset_values=$(echo "$response" | _egrep_o 'rrset_values.*\[.*\]' \ | ||
| _egrep_o '\[".*\"]') | ||
return 0 | ||
} | ||
|
||
_gandi_livedns_rest() { | ||
m=$1 | ||
ep="$2" | ||
|