Skip to content

Commit

Permalink
Allow macros to be a dict in service-apply-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoda-BZH committed Sep 8, 2021
1 parent 82ae0dc commit f668ff0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion library/Director/IcingaConfig/IcingaConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ public static function isValidMacroName($name)
&& ! preg_match('/\.$/', $name);
}

public static function isMacroDictionary($macroName, $whiteList = null)
{
$tokens = explode('.', $macroName);

return $whiteList === null || in_array($tokens[0], $whiteList);
}

public static function renderStringWithVariables($string, array $whiteList = null)
{
$len = strlen($string);
Expand All @@ -400,7 +407,7 @@ public static function renderStringWithVariables($string, array $whiteList = nul
// We got a macro
$macroName = substr($string, $start + 1, $i - $start - 1);
if (static::isValidMacroName($macroName)) {
if ($whiteList === null || in_array($macroName, $whiteList)) {
if ($whiteList === null || in_array($macroName, $whiteList) || static::isMacroDictionary($macroName, $whiteList)) {
if ($start > $offset) {
$parts[] = static::renderString(
substr($string, $offset, $start - $offset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public function testRenderStringWithVariables()
'"Before " + name1 + " " + name2 + " After"',
c::renderStringWithVariables('Before $name1$ $name2$ After')
);
$this->assertEquals(c::renderStringWithVariables('$config.bar$', ['config']), 'config.bar');
$this->assertEquals(c::renderStringWithVariables('foo $config.bar$', ['config']), '"foo " + config.bar');
$this->assertEquals(c::renderStringWithVariables('foo $quux.bar$', ['config']), '"foo $quux.bar$');
$this->assertEquals(c::renderStringWithVariables('foo $config.bar$', ['quux']), '"foo $config.bar$');
}

public function testRenderStringWithVariablesX()
Expand Down

0 comments on commit f668ff0

Please sign in to comment.