Improves error handling during certificate generation

This commit is contained in:
Lord Hepipud 2020-05-30 14:19:34 +02:00
parent c2e74e9781
commit 7551233f0b
2 changed files with 10 additions and 7 deletions

View file

@ -10,7 +10,8 @@ function Install-IcingaAgentCertificates()
); );
if ([string]::IsNullOrEmpty($Hostname)) { if ([string]::IsNullOrEmpty($Hostname)) {
throw 'Failed to install Icinga Agent certificates. Please provide a hostname'; Write-IcingaConsoleError 'Failed to install Icinga Agent certificates. Please provide a hostname';
return $FALSE;
} }
# Default for Icinga 2.8.0 and above # Default for Icinga 2.8.0 and above
@ -34,13 +35,14 @@ function Install-IcingaAgentCertificates()
); );
if ((Start-IcingaAgentCertificateProcess -Arguments $arguments) -eq $FALSE) { if ((Start-IcingaAgentCertificateProcess -Arguments $arguments) -eq $FALSE) {
throw 'Failed to generate host certificate'; Write-IcingaConsoleError 'Failed to generate host certificate';
return $FALSE;
} }
} }
if ([string]::IsNullOrEmpty($Endpoint) -And [string]::IsNullOrEmpty($CACert)) { if ([string]::IsNullOrEmpty($Endpoint) -And [string]::IsNullOrEmpty($CACert)) {
Write-IcingaConsoleWarning 'Your host certificates have been generated successfully. Please either specify an endpoint to connect to or provide the path to a valid ca.crt'; Write-IcingaConsoleWarning 'Your host certificates have been generated successfully. Please either specify an endpoint to connect to or provide the path to a valid ca.crt';
return $TRUE; return $FALSE;
} }
if (-Not [string]::IsNullOrEmpty($Endpoint)) { if (-Not [string]::IsNullOrEmpty($Endpoint)) {
@ -68,7 +70,7 @@ function Install-IcingaAgentCertificates()
Write-IcingaConsoleError 'Unable to connect to your provided Icinga CA. Please verify the entered configuration is correct.' ` Write-IcingaConsoleError 'Unable to connect to your provided Icinga CA. Please verify the entered configuration is correct.' `
'If you are not able to connect to your Icinga CA from this machine, you will have to provide the path' ` 'If you are not able to connect to your Icinga CA from this machine, you will have to provide the path' `
'to your Icinga ca.crt and use the CA-Proxy certificate handling.'; 'to your Icinga ca.crt and use the CA-Proxy certificate handling.';
return $TRUE; return $FALSE;
} }
} }
@ -88,7 +90,8 @@ function Install-IcingaAgentCertificates()
); );
if ((Start-IcingaAgentCertificateProcess -Arguments $arguments) -eq $FALSE) { if ((Start-IcingaAgentCertificateProcess -Arguments $arguments) -eq $FALSE) {
throw 'Failed to sign Icinga certificate'; Write-IcingaConsoleError 'Failed to sign Icinga certificate';
return $FALSE;
} }
if ([string]::IsNullOrEmpty($Ticket)) { if ([string]::IsNullOrEmpty($Ticket)) {

View file

@ -544,9 +544,9 @@ function Start-IcingaAgentInstallWizard()
} }
Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon'; Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon';
Install-IcingaAgentBaseFeatures; Install-IcingaAgentBaseFeatures;
Install-IcingaAgentCertificates -Hostname $Hostname -Endpoint $CAEndpoint -Port $CAPort -CACert $CAFile -Ticket $Ticket | Out-Null; $CertsInstalled = Install-IcingaAgentCertificates -Hostname $Hostname -Endpoint $CAEndpoint -Port $CAPort -CACert $CAFile -Ticket $Ticket;
Write-IcingaAgentApiConfig -Port $CAPort; Write-IcingaAgentApiConfig -Port $CAPort;
if ($EmptyCA -eq $TRUE) { if ($EmptyCA -eq $TRUE -Or $CertsInstalled -eq $FALSE) {
Disable-IcingaAgentFeature 'api'; Disable-IcingaAgentFeature 'api';
Write-IcingaConsoleWarning -Message '{0}{1}{2}{3}{4}' -Objects 'Your Icinga Agent API feature has been disabled. Please provide either your ca.crt ', Write-IcingaConsoleWarning -Message '{0}{1}{2}{3}{4}' -Objects 'Your Icinga Agent API feature has been disabled. Please provide either your ca.crt ',
'or connect to a parent node for certificate requests. You can run "Install-IcingaAgentCertificates" ', 'or connect to a parent node for certificate requests. You can run "Install-IcingaAgentCertificates" ',