mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
AssignRenderer: Add wildcard support and render with match()
This used MatchAny explicitly, since we check against an array here.
This commit is contained in:
parent
3bffe6a0d9
commit
e12cb9b7b9
@ -112,11 +112,24 @@ class AssignRenderer
|
||||
|
||||
protected function renderContains(FilterExpression $filter)
|
||||
{
|
||||
return sprintf(
|
||||
'%s in %s',
|
||||
$this->renderExpressionValue(json_decode($filter->getColumn())),
|
||||
$filter->getExpression()
|
||||
);
|
||||
// Note: expression and column is flipped in this mode
|
||||
$value = json_decode($filter->getColumn());
|
||||
$expression = $this->renderExpressionValue($value);
|
||||
$column = $filter->getExpression();
|
||||
|
||||
if (strpos($value, '*') !== false) {
|
||||
return sprintf(
|
||||
'match(%s, %s, MatchAny)',
|
||||
$expression,
|
||||
$column
|
||||
);
|
||||
} else {
|
||||
return sprintf(
|
||||
'%s in %s',
|
||||
$expression,
|
||||
$column
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function renderFilterExpression(FilterExpression $filter)
|
||||
|
@ -93,6 +93,15 @@ class AssignRendererTest extends BaseTestCase
|
||||
$expected,
|
||||
$this->renderer($string)->renderAssign()
|
||||
);
|
||||
|
||||
$string = json_encode('member*') . '=host.vars.some_array';
|
||||
|
||||
$expected = 'assign where match("member*", host.vars.some_array, MatchAny)';
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->renderer($string)->renderAssign()
|
||||
);
|
||||
}
|
||||
|
||||
public function testInArrayIsRenderedCorrectly()
|
||||
|
Loading…
x
Reference in New Issue
Block a user