81 lines
2.5 KiB
PowerShell
81 lines
2.5 KiB
PowerShell
function Get-ACMCertificateDetailsListByName {
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Retrieves a list of ACM certificate details by domain name.
|
|
|
|
.DESCRIPTION
|
|
Retrieves a list of ACM certificate details by domain name. Unfortunately, AWS did not accomodate
|
|
this use case when they wrote 'Get-ACMCertificateDetail' or 'Get-ACMCertificateList', and
|
|
'Get-ACMCertificateList' returns minimal information about the certificates -- just enough to know the
|
|
cert exists, but not enough to know anything useful about the certificate.
|
|
|
|
Note that this function returns an array because domain name uniqueness is not enforced in ACM.
|
|
|
|
.PARAMETER DomainName
|
|
[string] The domain name of the ACM certificates to retrieve.
|
|
|
|
.PARAMETER ProfileName
|
|
[string] The AWS profile to use during ACM queries.
|
|
|
|
.PARAMETER Region
|
|
[string] The AWS region to use during ACM queries.
|
|
|
|
.EXAMPLE
|
|
Get-ACMCertificateDetailsListByName -DomainName '*.sandbox.alkami.net' -ProfileName 'temp-prod' -Region 'us-east-1'
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
[OutputType([PSObject[]])]
|
|
param (
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string] $DomainName,
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string] $ProfileName,
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateScript({$_ -in (Get-AWSRegion).region})]
|
|
[string] $Region
|
|
)
|
|
|
|
$logLead = (Get-LogLeadName)
|
|
|
|
Import-AWSModule
|
|
|
|
try {
|
|
|
|
# Ref: https://docs.aws.amazon.com/powershell/latest/reference/items/Get-ACMCertificateList.html
|
|
$certList = ( Get-ACMCertificateList -ProfileName $ProfileName -Region $Region )
|
|
|
|
} catch {
|
|
|
|
Write-Error "$logLead : Unable to retrieve ACM certificate list from AWS : $($_.Exception.Message)"
|
|
return $null
|
|
}
|
|
|
|
$result = @()
|
|
$filteredCertList = $certList | Where-Object { $_.DomainName -eq $DomainName }
|
|
foreach ( $cert in $filteredCertList ) {
|
|
|
|
try {
|
|
|
|
# Ref: https://docs.aws.amazon.com/powershell/latest/reference/items/Get-ACMCertificateDetail.html
|
|
$result += ( Get-ACMCertificateDetail -CertificateArn $cert.CertificateArn -ProfileName $ProfileName -Region $Region )
|
|
|
|
} catch {
|
|
|
|
Write-Warning "$logLead : Unable to retrieve ACM certificate details for ARN [$($cert.CertificateArn)] : $($_.Exception.Message)"
|
|
}
|
|
}
|
|
|
|
if ( Test-IsCollectionNullOrEmpty -Collection $result ) {
|
|
|
|
Write-Warning "$logLead : No certificates found with a domain name of [$DomainName]."
|
|
}
|
|
|
|
|
|
return [PSObject[]]$result
|
|
} |