Fixes REST-Api to allow args with and without leading -

This commit is contained in:
Lord Hepipud 2023-07-24 11:51:59 +02:00
parent 57b21ef0ce
commit 014aae1985
2 changed files with 10 additions and 3 deletions

View file

@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#617](https://github.com/Icinga/icinga-powershell-framework/issues/617) Fixes failing calls for plugins which use a switch argument like `-NoPerfData`, which is followed directly by the `-ThresholdInterval` argument
* [#621](https://github.com/Icinga/icinga-powershell-framework/pull/621) Fixes `-ThresholdInterval` key detection on newer systems
* [#645](https://github.com/Icinga/icinga-powershell-framework/pull/645) Fixes error and exception handling while using API-Checks, which now will in most cases always return a proper check-result object and also abort while running into plugin execution errors, in case a server is not reachable by the time sync plugin for example
* [#646](https://github.com/Icinga/icinga-powershell-framework/pull/646) Fixes REST-Api to allow arguments for check execution with and without leading `-`
### Enhancements

View file

@ -99,16 +99,22 @@ function Invoke-IcingaApiChecksRESTCall()
# a valid hashtable, allowing us to parse arguments
# to our check command
$PSArguments.PSObject.Properties | ForEach-Object {
$CmdArgValue = $_.Value;
$CmdArgValue = $_.Value;
[string]$CmdArgName = $_.Name;
# Ensure we can use both, `-MyArgument` and `MyArgument` as valid input
if ($CmdArgName[0] -eq '-') {
$CmdArgName = $CmdArgName.Substring(1, $CmdArgName.Length - 1);
}
# Ensure we convert strings to SecureString, in case the plugin argument requires it
if ($CommandDetails.ContainsKey($_.Name) -And $CommandDetails[$_.Name] -Like 'SecureString') {
if ($CommandDetails.ContainsKey($CmdArgName) -And $CommandDetails[$CmdArgName] -Like 'SecureString') {
$CmdArgValue = ConvertTo-IcingaSecureString -String $_.Value;
}
Add-IcingaHashtableItem `
-Hashtable $Arguments `
-Key $_.Name `
-Key $CmdArgName `
-Value $CmdArgValue | Out-Null;
};