Merge pull request #256 from Icinga:fix/director_self_service_api_wizard

Fix: Self Service for removed hosts/keys inside Icinga Director

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
This commit is contained in:
Lord Hepipud 2021-05-27 16:15:17 +02:00 committed by GitHub
commit b782d44242
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 10 deletions

View file

@ -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

View file

@ -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,6 +54,19 @@ function Start-IcingaAgentDirectorWizard()
}
}
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 `
-DirectorUrl $DirectorUrl `
-SelfServiceAPIKey $TemplateKey `
-OverrideDirectorVars $OverrideDirectorVars `
-ForceTemplateKey;
}
} else {
try {
$Arguments = Get-IcingaDirectorSelfServiceConfig -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey;
} catch {
@ -61,8 +74,8 @@ function Start-IcingaAgentDirectorWizard()
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;
-OverrideDirectorVars $OverrideDirectorVars;
}
}
$Arguments = Convert-IcingaDirectorSelfServiceArguments -JsonInput $Arguments;