Rename 'config' to 'value' for items array/dictionary in apply-for-rule

This commit is contained in:
raviks789 2025-05-23 17:44:31 +02:00
parent c4201ba49c
commit a28a508e5e
No known key found for this signature in database
7 changed files with 13 additions and 12 deletions

View File

@ -680,8 +680,8 @@ class IcingaServiceForm extends DirectorObjectForm
'description' => $this->translate(
'Evaluates the apply for rule for ' .
'all objects with the custom attribute specified. ' .
'E.g selecting "host.vars.custom_attr" will generate "for (config in ' .
'host.vars.array_var)" where "config" will be accessible through "$config$". ' .
'E.g selecting "host.vars.custom_attr" will generate "for (value in ' .
'host.vars.array_var)" where "value" will be accessible through "$value$". ' .
'NOTE: only custom variables of type "Array" and "Dictionary" are eligible.'
)
]);
@ -698,7 +698,7 @@ class IcingaServiceForm extends DirectorObjectForm
if (! empty($dictionaryKeys)) {
$configVariables = new Table();
foreach ($dictionaryKeys as $label => $key) {
$configVariables->add([$label . ' (' . $key . ')', '=>', '$config.' . $key . '$']);
$configVariables->add([$label . ' (' . $key . ')', '=>', '$value.' . $key . '$']);
}
@ -709,7 +709,7 @@ class IcingaServiceForm extends DirectorObjectForm
[
Text::create($this->translate(
'Nested keys of selected host dictionary variable for apply-for-rule'
. ' are accessible through config as shown below:'
. ' are accessible through value as shown below:'
)),
$configVariables
]

View File

@ -46,11 +46,12 @@ class CustomVariableString extends CustomVariable
public function toConfigString($renderExpressions = false)
{
if ($renderExpressions) {
$whiteList = ['config'];
$whiteList = ['value'];
$value = $this->getValue();
if (
str_starts_with($value, '$')
&& str_ends_with($value, '$')
&& str_contains($value, 'value.')
) {
$whiteList[] = trim($value, '$');
}

View File

@ -365,7 +365,7 @@ class IcingaService extends IcingaObject implements ExportInterface
if ($this->isApplyRuleforDictionary(substr($this->get('apply_for'), strlen('host.vars.')))) {
$applyForConfig = sprintf(
"%s %s%s for (key => config in %s) {\n",
"%s %s%s for (key => value in %s) {\n",
$this->getObjectTypeName(),
$this->getType(),
$name,
@ -373,7 +373,7 @@ class IcingaService extends IcingaObject implements ExportInterface
);
} else {
$applyForConfig = sprintf(
"%s %s%s for (config in %s) {\n",
"%s %s%s for (value in %s) {\n",
$this->getObjectTypeName(),
$this->getType(),
$name,

View File

@ -218,7 +218,7 @@ class IcingaServiceTest extends BaseTestCase
(string) $service
);
$service->object_name = '___TEST$config$___service $host.var.bla$';
$service->object_name = '___TEST$value$___service $host.var.bla$';
$this->assertEquals(
$this->loadRendered('service6'),
(string) $service

View File

@ -1,4 +1,4 @@
apply Service "___TEST___service" for (config in host.vars.test1) {
apply Service "___TEST___service" for (value in host.vars.test1) {
display_name = "Whatever service"
assign where host.vars.env == "test"
vars.test1 = "string"

View File

@ -1,5 +1,5 @@
apply Service for (config in host.vars.test1) {
name = "___TEST" + config + "___service " + host.var.bla
apply Service for (value in host.vars.test1) {
name = "___TEST" + value + "___service " + host.var.bla
display_name = "Whatever service"
assign where host.vars.env == "test"
vars.test1 = "string"

View File

@ -1,4 +1,4 @@
apply Service for (config in host.vars.test1) {
apply Service for (value in host.vars.test1) {
display_name = "Whatever service"
assign where host.vars.env == "test"
vars.test1 = "string"