diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index 4045d51..c682741 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -25,6 +25,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic ### Bugfixes +* [#231](https://github.com/Icinga/icinga-powershell-framework/issues/231) Fixes error while using Icinga Director Self-Service API, in case the host or host API key was deleted inside the Icinga Director and the installation wizard was called with the correct template key, while the old host key was still present inside the Icinga for Windows configuration * [#232](https://github.com/Icinga/icinga-powershell-framework/pull/232) Fixes wrong encoding while using REST-Api checks experimental feature, and now forces UTF8 * [#240](https://github.com/Icinga/icinga-powershell-framework/pull/240) While filtering for certain services with `Get-IcingaServices`, there were some attributes missing from the collection. These are now added resulting in always correct output data. * [#245](https://github.com/Icinga/icinga-powershell-framework/pull/245) Fixes loading of `.pfx` certificates by properly checking the file type diff --git a/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 b/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 index 21b09b4..2ec1ddf 100644 --- a/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 +++ b/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 @@ -5,10 +5,10 @@ function Start-IcingaAgentDirectorWizard() [string]$SelfServiceAPIKey = $null, $OverrideDirectorVars = $null, [bool]$RunInstaller = $FALSE, - [switch]$ForceTemplateKey + [switch]$ForceTemplateKey = $FALSE ); - [hashtable]$DirectorOverrideArgs = @{} + [hashtable]$DirectorOverrideArgs = @{ } if ([string]::IsNullOrEmpty($DirectorUrl)) { $DirectorUrl = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the Url pointing to your Icinga Director (Example: "https://example.com/icingaweb2/director")' -Default 'v').answer; } @@ -54,15 +54,28 @@ function Start-IcingaAgentDirectorWizard() } } - try { - $Arguments = Get-IcingaDirectorSelfServiceConfig -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey; - } catch { - Write-IcingaConsoleError ([string]::Format('Failed to connect to your Icinga Director at "{0}". Please try again', $DirectorUrl)); + if ([string]::IsNullOrEmpty($LocalAPIKey) -eq $FALSE -And $LocalAPIKey -ne $TemplateKey -And $ForceTemplateKey -eq $FALSE) { + try { + $Arguments = Get-IcingaDirectorSelfServiceConfig -DirectorUrl $DirectorUrl -ApiKey $LocalAPIKey; + } catch { + Write-IcingaConsoleError 'Your local stored host key is no longer valid. Using provided template key'; - return Start-IcingaAgentDirectorWizard ` - -SelfServiceAPIKey ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Please re-enter your SelfService API Key for the Host-Template in case the key is no longer assigned to your host' -Default 'v' -DefaultInput $SelfServiceAPIKey).answer) ` - -OverrideDirectorVars $OverrideDirectorVars ` - -ForceTemplateKey; + return Start-IcingaAgentDirectorWizard ` + -DirectorUrl $DirectorUrl ` + -SelfServiceAPIKey $TemplateKey ` + -OverrideDirectorVars $OverrideDirectorVars ` + -ForceTemplateKey; + } + } else { + try { + $Arguments = Get-IcingaDirectorSelfServiceConfig -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey; + } catch { + Write-IcingaConsoleError ([string]::Format('Failed to connect to your Icinga Director at "{0}". Please try again', $DirectorUrl)); + + return Start-IcingaAgentDirectorWizard ` + -SelfServiceAPIKey ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Please re-enter your SelfService API Key for the Host-Template in case the key is no longer assigned to your host' -Default 'v' -DefaultInput $SelfServiceAPIKey).answer) ` + -OverrideDirectorVars $OverrideDirectorVars; + } } $Arguments = Convert-IcingaDirectorSelfServiceArguments -JsonInput $Arguments;