Skip to content

Commit

Permalink
Fix WEDOS plugin to handle different response types for dns-domains-l…
Browse files Browse the repository at this point in the history
…ist API call (#579)
  • Loading branch information
radmax authored Nov 11, 2024
1 parent e88a265 commit b516a54
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions Posh-ACME/Plugins/WEDOS.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Add-DnsTxt {
rdata = $TxtValue
ttl = 300 # minimum
}
Invoke-Wedos dns-row-add $WedosCredential -Data $data
$null = Invoke-Wedos dns-row-add $WedosCredential -Data $data
if ($zone -notin $script:WedosZonesToSave) {
$script:WedosZonesToSave += $zone
}
Expand Down Expand Up @@ -97,7 +97,7 @@ function Remove-DnsTxt {
domain = $zone
row_id = $rec.ID
}
Invoke-Wedos dns-row-delete $WedosCredential -Data $data
$null = Invoke-Wedos dns-row-delete $WedosCredential -Data $data
if ($zone -notin $script:WedosZonesToSave) {
$script:WedosZonesToSave += $zone
}
Expand Down Expand Up @@ -143,7 +143,7 @@ function Save-DnsTxt {
$data = @{
name = $zone
}
Invoke-Wedos dns-domain-commit $WedosCredential -Data $data
$null = Invoke-Wedos dns-domain-commit $WedosCredential -Data $data
}
$script:WedosZonesToSave = @()

Expand Down Expand Up @@ -260,8 +260,37 @@ function Find-Zone {
}

# Get all of the domains on the account
$zones = Invoke-Wedos dns-domains-list $Credential | Select-Object -Expand domain
if (-not $zones) {
$resp = Invoke-Wedos dns-domains-list $Credential

# For some unknown reason, the dns-domains-list command can returns the domain data
# in two different ways. It seems to be account specific, but we don't have enough
# sample data to know why a given account uses one format or another. Maybe region
# specific? Maybe age of the account?
# Regardless, we need to account for both potential responses to get the zone data.
# Example 1: An array of zone objects
# {
# "domain": [
# {"name": "example.com", "type": "primary", "status": "active"},
# {"name": "example.net", "type": "primary", "status": "active"}
# ]
# }
# Example 2: And object with numeric keys and zone object values
# {
# "domain": {
# "24": {"name": "example.com", "type": "primary", "status": "active"},
# "11": {"name": "example.net", "type": "primary", "status": "active"}
# }
# }
if ($resp.domain -is [array]) {
# We can use the array as-is
$zones = @($resp.domain)
} else {
# The only properties should be zone objects, so just get them all
$zones = @($resp.domain.PSObject.Properties | ForEach-Object { $_.Value })
}
Write-Debug "Found domains: $($zones | ConvertTo-Json)"

if ($zones.Count -eq 0) {
Write-Warning "No WEDOS hosted domains found."
return
}
Expand Down

0 comments on commit b516a54

Please sign in to comment.