Skip to content

Commit

Permalink
Add support for Hurricane Electric's Dynamic TXT API to update TXT-re…
Browse files Browse the repository at this point in the history
…cord (#494)
  • Loading branch information
jbrunink authored Aug 25, 2023
1 parent b4e416a commit a549695
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 70 deletions.
128 changes: 128 additions & 0 deletions Posh-ACME/Plugins/HurricaneElectricDyn.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
function Get-CurrentPluginType { 'dns-01' }

function Add-DnsTxt {
[CmdletBinding()]
param(
[Parameter(Mandatory,Position=0)]
[string]$RecordName,
[Parameter(Mandatory,Position=1)]
[string]$TxtValue,
[Parameter(Mandatory)]
[pscredential[]]$HEDynCredential,
[Parameter(ValueFromRemainingArguments)]
$ExtraParams
)

Write-Verbose "Adding a TXT record for $RecordName with value $TxtValue"

# get the cred that matches the record
$cred = $HEDynCredential | Where-Object { $RecordName -eq $_.UserName }
if (-not $cred) {
throw "HEDynCredential did not contain any matches for $RecordName."
}

# get plain text password we can work with
$HEPassword = $cred.GetNetworkCredential().Password

# build the post query
$queryParams = @{
Uri = 'https://dyn.dns.he.net/nic/update'
Method = 'Post'
Body = @{
hostname = $RecordName
password = $HEPassword
txt = $TxtValue
}
ErrorAction = 'Stop'
Verbose = $false
}

try {
Write-Debug "POST $($queryParams.Uri)`nhostname = $RecordName, txt = $TxtValue"
$response = Invoke-RestMethod @queryParams @script:UseBasic
} catch { throw }

if ($response -notmatch '^(nochg|good)') {
throw "Unexpected result status while adding record: $response"
}

<#
.SYNOPSIS
Add a DNS TXT record to Hurricane Electric using their Dynamic TXT API.
.DESCRIPTION
Add a DNS TXT record to Hurricane Electric using their Dynamic TXT API.
.PARAMETER RecordName
The fully qualified name of the TXT record.
.PARAMETER TxtValue
The value of the TXT record.
.PARAMETER HEDynCredential
One or more PSCredential objects where the username is the full DNS record
name being updated and the password is the key/password for dynamically
updating that record.
.PARAMETER ExtraParams
This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports.
.EXAMPLE
Add-DnsTxt '_acme-challenge.example.com' 'txt-value' -HEDynCredential (Get-Credential)
Adds a TXT record using after providing credentials in a prompt.
#>
}

function Remove-DnsTxt {
[CmdletBinding()]
param(
[Parameter(Mandatory,Position=0)]
[string]$RecordName,
[Parameter(Mandatory,Position=1)]
[string]$TxtValue,
[Parameter(Mandatory)]
[pscredential[]]$HEDynCredential,
[Parameter(ValueFromRemainingArguments)]
$ExtraParams
)
<#
.SYNOPSIS
Not required
.DESCRIPTION
This provider does not really support deleting the TXT record that was created.
.PARAMETER RecordName
The fully qualified name of the TXT record.
.PARAMETER TxtValue
The value of the TXT record.
.PARAMETER HEDynCredential
One or more PSCredential objects where the username is the full DNS record
name being updated and the password is the key/password for dynamically
updating that record.
.PARAMETER ExtraParams
This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports.
#>
}

function Save-DnsTxt {
[CmdletBinding()]
param(
[Parameter(ValueFromRemainingArguments)]
$ExtraParams
)
<#
.SYNOPSIS
Not required
.DESCRIPTION
This provider does not require calling this function to save DNS records.
.PARAMETER ExtraParams
This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports.
#>
}
Loading

0 comments on commit a549695

Please sign in to comment.