From a28a508e5ef31d6b05d981f0dc714c574a22b328 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Fri, 23 May 2025 17:44:31 +0200 Subject: [PATCH] Rename 'config' to 'value' for items array/dictionary in apply-for-rule --- application/forms/IcingaServiceForm.php | 8 ++++---- library/Director/CustomVariable/CustomVariableString.php | 3 ++- library/Director/Objects/IcingaService.php | 4 ++-- test/php/library/Director/Objects/IcingaServiceTest.php | 2 +- test/php/library/Director/Objects/rendered/service5.out | 2 +- test/php/library/Director/Objects/rendered/service6.out | 4 ++-- test/php/library/Director/Objects/rendered/service7.out | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php index 56b5b718..f7ad8552 100644 --- a/application/forms/IcingaServiceForm.php +++ b/application/forms/IcingaServiceForm.php @@ -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 ] diff --git a/library/Director/CustomVariable/CustomVariableString.php b/library/Director/CustomVariable/CustomVariableString.php index 143bf6ad..e4012da8 100644 --- a/library/Director/CustomVariable/CustomVariableString.php +++ b/library/Director/CustomVariable/CustomVariableString.php @@ -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, '$'); } diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php index 77412487..d0dfd1a6 100644 --- a/library/Director/Objects/IcingaService.php +++ b/library/Director/Objects/IcingaService.php @@ -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, diff --git a/test/php/library/Director/Objects/IcingaServiceTest.php b/test/php/library/Director/Objects/IcingaServiceTest.php index 3005349e..8ac10b14 100644 --- a/test/php/library/Director/Objects/IcingaServiceTest.php +++ b/test/php/library/Director/Objects/IcingaServiceTest.php @@ -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 diff --git a/test/php/library/Director/Objects/rendered/service5.out b/test/php/library/Director/Objects/rendered/service5.out index b05e6301..b186d5ab 100644 --- a/test/php/library/Director/Objects/rendered/service5.out +++ b/test/php/library/Director/Objects/rendered/service5.out @@ -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" diff --git a/test/php/library/Director/Objects/rendered/service6.out b/test/php/library/Director/Objects/rendered/service6.out index fdca11c4..e0689669 100644 --- a/test/php/library/Director/Objects/rendered/service6.out +++ b/test/php/library/Director/Objects/rendered/service6.out @@ -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" diff --git a/test/php/library/Director/Objects/rendered/service7.out b/test/php/library/Director/Objects/rendered/service7.out index c125ccce..c447dcb7 100644 --- a/test/php/library/Director/Objects/rendered/service7.out +++ b/test/php/library/Director/Objects/rendered/service7.out @@ -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"