Skip to content

Commit 9d14973

Browse files
committed
Gandi: update API URL for new livedns endpoint and make it configurable (#682)
1 parent da950f5 commit 9d14973

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

‎Posh-ACME/Plugins/Gandi.ps1‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function Add-DnsTxt {
1313
[securestring]$GandiToken,
1414
[Parameter(ParameterSetName='DeprecatedInsecure',Mandatory,Position=2)]
1515
[string]$GandiTokenInsecure,
16+
[string]$GandiApiBaseUrl = 'https://api.gandi.net/v5/livedns',
1617
[Parameter(ValueFromRemainingArguments)]
1718
$ExtraParams
1819
)
@@ -31,13 +32,13 @@ function Add-DnsTxt {
3132
}
3233

3334
# get the zone name for our record
34-
$zoneName = Find-GandiZone $RecordName $RestHeaders
35+
$zoneName = Find-GandiZone $RecordName $RestHeaders $GandiApiBaseUrl
3536
Write-Debug "Found zone $zoneName"
3637

3738
# find the matching TXT record if it exists
3839
$recShort = $RecordName -ireplace "\.?$([regex]::Escape($zoneName.TrimEnd('.')))$",''
3940
if (-not $recShort) { $recShort = '@' }
40-
$recUrl = "https://dns.api.gandi.net/api/v5/domains/$zoneName/records/$recShort/TXT"
41+
$recUrl = "$GandiApiBaseUrl/domains/$zoneName/records/$recShort/TXT"
4142
try {
4243
$queryParams = @{
4344
Uri = $recUrl
@@ -100,6 +101,9 @@ function Add-DnsTxt {
100101
.PARAMETER GandiTokenInsecure
101102
(DEPRECATED) The API token for your Gandi account.
102103
104+
.PARAMETER GandiApiBaseUrl
105+
(Optional) The base URL for the Gandi API. Defaults to 'https://api.gandi.net/v5/livedns' and should only be changed if Gandi changes their API URL.
106+
103107
.PARAMETER ExtraParams
104108
This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports.
105109
@@ -124,6 +128,7 @@ function Remove-DnsTxt {
124128
[securestring]$GandiToken,
125129
[Parameter(ParameterSetName='DeprecatedInsecure',Mandatory,Position=2)]
126130
[string]$GandiTokenInsecure,
131+
[string]$GandiApiBaseUrl = 'https://api.gandi.net/v5/livedns',
127132
[Parameter(ValueFromRemainingArguments)]
128133
$ExtraParams
129134
)
@@ -142,13 +147,13 @@ function Remove-DnsTxt {
142147
}
143148

144149
# get the zone name for our record
145-
$zoneName = Find-GandiZone $RecordName $RestHeaders
150+
$zoneName = Find-GandiZone $RecordName $RestHeaders $GandiApiBaseUrl
146151
Write-Debug "Found zone $zoneName"
147152

148153
# find the matching TXT record if it exists
149154
$recShort = $RecordName -ireplace "\.?$([regex]::Escape($zoneName.TrimEnd('.')))$",''
150155
if (-not $recShort) { $recShort = '@' }
151-
$recUrl = "https://dns.api.gandi.net/api/v5/domains/$zoneName/records/$recShort/TXT"
156+
$recUrl = "$GandiApiBaseUrl/domains/$zoneName/records/$recShort/TXT"
152157
try {
153158
$queryParams = @{
154159
Uri = $recUrl
@@ -213,6 +218,9 @@ function Remove-DnsTxt {
213218
.PARAMETER GandiTokenInsecure
214219
(DEPRECATED) The API token for your Gandi account.
215220
221+
.PARAMETER GandiApiBaseUrl
222+
(Optional) The base URL for the Gandi API. Defaults to 'https://api.gandi.net/v5/livedns' and should only be changed if Gandi changes their API URL.
223+
216224
.PARAMETER ExtraParams
217225
This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports.
218226
@@ -255,7 +263,9 @@ function Find-GandiZone {
255263
[Parameter(Mandatory,Position=0)]
256264
[string]$RecordName,
257265
[Parameter(Mandatory,Position=1)]
258-
[hashtable]$RestHeaders
266+
[hashtable]$RestHeaders,
267+
[Parameter(Position=2)]
268+
[string]$ApiBaseUrl = 'https://api.gandi.net/v5/livedns'
259269
)
260270

261271
# setup a module variable to cache the record to zone mapping
@@ -281,7 +291,7 @@ function Find-GandiZone {
281291
$zoneTest = $pieces[$i..($pieces.Count-1)] -join '.'
282292
try {
283293
$queryParams = @{
284-
Uri = "https://dns.api.gandi.net/api/v5/domains/$zoneTest"
294+
Uri = "$ApiBaseUrl/domains/$zoneTest"
285295
Headers = $RestHeaders
286296
Verbose = $false
287297
ErrorAction = 'Stop'

0 commit comments

Comments
 (0)