Adds DSL parser to string arguments, fixing errors

This commit is contained in:
Lord Hepipud 2022-02-09 14:10:52 +01:00
parent a83d35e60e
commit f126065cad
2 changed files with 25 additions and 2 deletions

View file

@ -13,6 +13,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Bugfixes
* [#473](https://github.com/Icinga/icinga-powershell-framework/pull/473) Fixes an issue with current string rendering config implementation, as string values containing whitespaces or `$` are rendered wrong by default, if not set in single quotes `''`
* [#476](https://github.com/Icinga/icinga-powershell-framework/pull/476) Fixes exception `You cannot call a method on va null-valued expression` during installation in case no background daemon is configured
* [#529](https://github.com/Icinga/icinga-powershell-framework/pull/529) Fixes package manifest reader for Icinga for Windows components on Windows 2012 R2 and older
* [#523](https://github.com/Icinga/icinga-powershell-framework/pull/523) Fixes errors on encapsulated PowerShell calls for missing Cmdlets `Write-IcingaConsoleError` and `Optimize-IcingaForWindowsMemory`

View file

@ -268,6 +268,26 @@ function Get-IcingaCheckCommandConfig()
'order' = $Order;
}
);
} elseif ($parameter.type.name -eq 'String') {
# Conditional whether type of parameter is String
$Basket.Command[$check].arguments.Add(
[string]::Format('-{0}', $parameter.Name), @{
'value' = @{
'type' = 'Function';
'body' = [string]::Format(
'var str = macro("{0}");{1}var argLen = len(str);{1}{1}if (argLen == 0) {2}{1} return;{1}{3}{1}{1}if (argLen != 0 && str.substr(0,1) == "{4}" && str.substr(argLen - 1, argLen) == "{4}") {2}{1} return str;{1}{3}{1}{1}return ("{4}" + str + "{4}");',
$IcingaCustomVariable,
"`r`n",
'{',
'}',
"'"
);
}
'set_if' = [string]::Format('var str = macro("{0}"); if (len(str) == 0) {{ return false; }}; return true;', $IcingaCustomVariable);
'set_if_format' = 'expression';
'order' = $Order;
}
);
} elseif ($parameter.type.name -eq 'SecureString') {
# Convert out input string as SecureString
$Basket.Command[$check].arguments.Add(
@ -528,6 +548,8 @@ function Write-IcingaPlainConfigurationFiles()
# Order is numeric -> no "" required
if ($argconfig -eq 'order') {
$StringFormater = ' {0} = {1}{2}';
} elseif ($argconfig -eq 'set_if' -And $CheckArgument[$argconfig] -Like '*var str = macro*') {
$StringFormater = ' {0} = {{{{{2} {1}{2} }}}}{2}';
} else {
# All other entries should be handled as strings and contain ""
$StringFormater = ' {0} = "{1}"{2}'