Skip to content

Commit

Permalink
fix for #9 with New-PACertificate redownloading completed certs
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbolger committed May 4, 2018
1 parent 10cdafc commit 619ff64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Posh-ACME/Public/New-PACertificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function New-PACertificate {
# The order should now be finalized and the status should be valid. The only
# thing left to do is download the cert and chain and write the results to
# disk
if ($order.status -eq 'valid') {
if ($order.status -eq 'valid' -and !$order.Complete) {
if ([string]::IsNullOrWhiteSpace($order.certificate)) {
throw "Order status is valid, but no certificate URL was found."
}
Expand All @@ -129,10 +129,22 @@ function New-PACertificate {
$certExpires = (Import-Pem $certFile).NotAfter
$script:Order.CertExpires = $certExpires.ToString('yyyy-MM-ddTHH:mm:ssZ')
$script:Order.RenewAfter = $certExpires.AddDays(-30).ToString('yyyy-MM-ddTHH:mm:ssZ')
Update-PAOrder -SaveOnly

Write-Verbose "Successfully created certificate."
Write-Host "Certificate files saved to $($script:OrderFolder)"

# since there's no easy way to tell that we've already downloaded the finalized cert
# we'll add our own boolean to the order object to keep track
if ('Complete' -notin $order.PSObject.Properties.Name) {
$script:Order | Add-Member -MemberType NoteProperty -Name 'Complete' -Value $true
} else {
$script:Order.Complete = $true
}

Update-PAOrder -SaveOnly

} elseif ($order.Complete) {
Write-Verbose "This order has already been completed."
}


Expand Down
1 change: 1 addition & 0 deletions Posh-ACME/Public/New-PAOrder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function New-PAOrder {
$order | Add-Member -MemberType NoteProperty -Name 'DnsAlias' -Value $null
$order | Add-Member -MemberType NoteProperty -Name 'DnsSleep' -Value $null
$order | Add-Member -MemberType NoteProperty -Name 'ValidationTimeout' -Value $null
$order | Add-Member -MemberType NoteProperty -Name 'Complete' -Value $false

# make sure there's a certificate field for later
if ('certificate' -notin $order.PSObject.Properties.Name) {
Expand Down

0 comments on commit 619ff64

Please sign in to comment.