Pipelines/Steps/Install/OnPrem/Solr/SSL/New-ServerCert.ps1

$ErrorActionPreference = "Stop"

$prefix = $SAFConfiguration.prefix
$hostNames = @()

if (![string]::IsNullOrEmpty($SAFConfiguration.ssl.hostNames)) {
    $hostNames = $SAFConfiguration.ssl.hostNames
}
elseif ($SAFConfiguration.system.serverRole -eq "AllInOneQuickly") {
    $hostNames += $SAFConfiguration.search.solr.hostName
}

if($hostNames.Length -eq 0) {
    throw "Please, provide Host names for SSL generation..."
}

$exportPath = Get-Location
$rootCertName = BuildSolrRootCertName -Prefix $prefix
$serverCertName = BuildSolrServerCertName -Prefix $prefix

$certDestPath = Join-Path -Path $exportPath -ChildPath "SolrServerSSLCertificate_SAF.pfx"
if (Test-Path $certDestPath) {
    Write-Warning "It seems that you alredy have SolrServerSSLCertificate_SAF.pfx SSL certificate. Skipping creation..."
    Start-Sleep -s 5
}
else{
    GenerateServerCert -RootCertName $rootCertName -ServerCertName $serverCertName -Hostnames $hostNames
    ExportCert -CertName $serverCertName -PfxName "SolrServerSSLCertificate_SAF.pfx" -ExportPath $exportPath -Password $SAFDefaultPFXPassword
}