diff --git a/policies/rudderc/src/backends/windows.rs b/policies/rudderc/src/backends/windows.rs index c3b6f564691..5d938d48ef6 100644 --- a/policies/rudderc/src/backends/windows.rs +++ b/policies/rudderc/src/backends/windows.rs @@ -377,20 +377,20 @@ mod tests { assert_eq!(res, r); let c = "${var}"; - let r = "([Rudder.Condition]::canonify([Rudder.Datastate]::Render('{{' + @'\n\ + let r = "([Rudder.Condition]::canonify([Rudder.Datastate]::Render('{{&' + @'\n\ vars.var\n\ '@ + '}}')))"; let res = canonify_condition(c).unwrap(); assert_eq!(res, r); let c = "${my_cond}.debian|${sys.${plouf}}"; - let r = r#"([Rudder.Condition]::canonify(([Rudder.Datastate]::Render('{{' + @' + let r = r#"([Rudder.Condition]::canonify(([Rudder.Datastate]::Render('{{&' + @' vars.my_cond '@ + '}}')) + @' .debian| -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. -'@ + [Rudder.Datastate]::Render('{{' + @' +'@ + [Rudder.Datastate]::Render('{{&' + @' vars.plouf '@ + '}}') + '}}'))))"#; let res = canonify_condition(c).unwrap(); @@ -463,7 +463,7 @@ a simple test assert_eq!( "@' a less simple -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.plouf.plouf '@ + '}}')) + @' test @@ -480,7 +480,7 @@ vars.plouf.plouf assert_eq!( "@' a less simple -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.technique_id.param1 '@ + '}}')) + @' test @@ -497,7 +497,7 @@ vars.technique_id.param1 assert_eq!( "@' a less simple -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.plouf.param1 '@ + '}}')) + @' test @@ -514,7 +514,7 @@ vars.plouf.param1 assert_eq!( "@' a less simple -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.param1or2 '@ + '}}')) + @' test @@ -531,7 +531,7 @@ vars.param1or2 assert_eq!( "@' a less simple -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys.host '@ + '}}')) + @' test @@ -548,7 +548,7 @@ vars.sys.host assert_eq!( "@' a less simple -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.const.n '@ + '}}')) + @' test diff --git a/policies/rudderc/src/ir/value.rs b/policies/rudderc/src/ir/value.rs index 8fdece09942..c644dd59d91 100644 --- a/policies/rudderc/src/ir/value.rs +++ b/policies/rudderc/src/ir/value.rs @@ -64,7 +64,7 @@ pub fn known_vars() -> &'static serde_yaml::Value { } fn nustache_render(s: &str) -> String { - format!("[Rudder.Datastate]::Render('{{{{' + {} + '}}}}')", s) + format!("[Rudder.Datastate]::Render('{{{{&' + {} + '}}}}')", s) } /// Rudder variable expression. @@ -806,7 +806,7 @@ mod tests { a.fmt(Target::Windows), r###"@' /bin/true "# -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.node.inventory.os.fullName '@ + '}}')) + @' " @@ -820,7 +820,7 @@ vars.node.inventory.os.fullName assert_eq!(b.fmt(Target::Unix), "${node.properties[a][b]}"); assert_eq!( b.fmt(Target::Windows), - r#"[Rudder.Datastate]::Render('{{' + @' + r#"[Rudder.Datastate]::Render('{{&' + @' vars.node.properties.a.b '@ + '}}')"# ); @@ -829,7 +829,7 @@ vars.node.properties.a.b assert_eq!(c.fmt(Target::Unix), "${sys.host}"); assert_eq!( c.fmt(Target::Windows), - r#"[Rudder.Datastate]::Render('{{' + @' + r#"[Rudder.Datastate]::Render('{{&' + @' vars.sys.host '@ + '}}')"# ); @@ -850,11 +850,11 @@ host assert_eq!(d.fmt(Target::Unix), "${node.properties[inner${sys.host}]}"); assert_eq!( d.fmt(Target::Windows), - r#"[Rudder.Datastate]::Render('{{' + @' + r#"[Rudder.Datastate]::Render('{{&' + @' vars.node.properties. '@ + @' inner -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys.host '@ + '}}')) + '}}')"# ); @@ -867,11 +867,11 @@ vars.sys.host ])]); assert_eq!( dd.fmt(Target::Windows), - r#"[Rudder.Datastate]::Render('{{' + @' + r#"[Rudder.Datastate]::Render('{{&' + @' vars.node.properties. '@ + @' inner -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. '@ + @' host @@ -886,7 +886,7 @@ host assert_eq!(ee.fmt(Target::Unix), "${node.properties[interfaces][eth0]}"); assert_eq!( ee.fmt(Target::Windows), - r#"[Rudder.Datastate]::Render('{{' + @' + r#"[Rudder.Datastate]::Render('{{&' + @' vars.node.properties. '@ + @' interfaces @@ -914,17 +914,17 @@ eth0 ]); assert_eq!( e.fmt(Target::Windows), - r#"[Rudder.Datastate]::Render('{{' + @' + r#"[Rudder.Datastate]::Render('{{&' + @' vars.node.properties. -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.node.properties. '@ + @' inner -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. '@ + @' host -'@ + '}}')) + ([Rudder.Datastate]::Render('{{' + @' +'@ + '}}')) + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. '@ + @' interfaces @@ -950,9 +950,9 @@ tutu ])])]); assert_eq!( e.fmt(Target::Windows), - r#"([Rudder.Datastate]::Render('{{' + @' + r#"([Rudder.Datastate]::Render('{{&' + @' vars.sys. -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars. '@ + @' host @@ -965,7 +965,7 @@ host ]); assert_eq!( e.fmt(Target::Windows), - r#"[Rudder.Datastate]::Render('{{' + @' + r#"[Rudder.Datastate]::Render('{{&' + @' vars.bundle.plouf.key '@ + '}}')"# .to_string() @@ -980,7 +980,7 @@ vars.bundle.plouf.key f.fmt(Target::Windows), r#"@' bundle.plouf is -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.bundle.plouf '@ + '}}'))"# .to_string() diff --git a/policies/rudderc/tests/cases/general/escaping/technique.ps1 b/policies/rudderc/tests/cases/general/escaping/technique.ps1 index 1c58829611c..dbb54664603 100644 --- a/policies/rudderc/tests/cases/general/escaping/technique.ps1 +++ b/policies/rudderc/tests/cases/general/escaping/technique.ps1 @@ -27,13 +27,13 @@ $reportId=$reportIdBase + "a86ce2e5-d5b6-45cc-87e8-c11cca71d966" try { - $componentKey = ([Rudder.Datastate]::Render('{{' + @' + $componentKey = ([Rudder.Datastate]::Render('{{&' + @' vars.sys.host '@ + '}}')) + @' . | / -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. -'@ + [Rudder.Datastate]::Render('{{' + @' +'@ + [Rudder.Datastate]::Render('{{&' + @' vars.host '@ + '}}') + '}}')) + @' ' '' ''' $ $$ " "" \ \\😋aà3 @@ -42,13 +42,13 @@ vars.host $reportParams = @{ ClassPrefix = ([Rudder.Condition]::canonify(("package_present_" + $componentKey))) ComponentKey = $componentKey - ComponentName = ([Rudder.Datastate]::Render('{{' + @' + ComponentName = ([Rudder.Datastate]::Render('{{&' + @' vars.sys.host '@ + '}}')) + @' . | / -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. -'@ + [Rudder.Datastate]::Render('{{' + @' +'@ + [Rudder.Datastate]::Render('{{&' + @' vars.host '@ + '}}') + '}}')) + @' ' '' ''' $ $$ " "" \ \\😋aà3 @@ -60,25 +60,25 @@ vars.host TechniqueName = $techniqueName } - $class = ([Rudder.Condition]::canonify(([Rudder.Datastate]::Render('{{' + @' + $class = ([Rudder.Condition]::canonify(([Rudder.Datastate]::Render('{{&' + @' vars.my_cond '@ + '}}')) + @' .debian| -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. -'@ + [Rudder.Datastate]::Render('{{' + @' +'@ + [Rudder.Datastate]::Render('{{&' + @' vars.plouf '@ + '}}') + '}}')))) if ([Rudder.Datastate]::Evaluate($class)) { $methodParams = @{ Architecture = '' - Name = ([Rudder.Datastate]::Render('{{' + @' + Name = ([Rudder.Datastate]::Render('{{&' + @' vars.sys.host '@ + '}}')) + @' . | / -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. -'@ + [Rudder.Datastate]::Render('{{' + @' +'@ + [Rudder.Datastate]::Render('{{&' + @' vars.host '@ + '}}') + '}}')) + @' ' '' ''' $ $$ " "" \ \\😋aà3 @@ -117,13 +117,13 @@ if(Get-Service "Zabbix agent") { write-output "exists" } $reportId=$reportIdBase + "a86ce2e5-d5b6-45cc-87e8-c11cca71d977" try { - $componentKey = ([Rudder.Datastate]::Render('{{' + @' + $componentKey = ([Rudder.Datastate]::Render('{{&' + @' vars.sys.host '@ + '}}')) + @' . | / -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. -'@ + [Rudder.Datastate]::Render('{{' + @' +'@ + [Rudder.Datastate]::Render('{{&' + @' vars.host '@ + '}}') + '}}')) + @' ' '' ''' $ $$ " "" \ \\😋aà3 @@ -132,13 +132,13 @@ vars.host $reportParams = @{ ClassPrefix = ([Rudder.Condition]::canonify(("package_present_" + $componentKey))) ComponentKey = $componentKey - ComponentName = ([Rudder.Datastate]::Render('{{' + @' + ComponentName = ([Rudder.Datastate]::Render('{{&' + @' vars.sys.host '@ + '}}')) + @' . | / -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. -'@ + [Rudder.Datastate]::Render('{{' + @' +'@ + [Rudder.Datastate]::Render('{{&' + @' vars.host '@ + '}}') + '}}')) + @' ' '' ''' $ $$ " "" \ \\😋aà3 @@ -152,13 +152,13 @@ vars.host $methodParams = @{ Architecture = '' - Name = ([Rudder.Datastate]::Render('{{' + @' + Name = ([Rudder.Datastate]::Render('{{&' + @' vars.sys.host '@ + '}}')) + @' . | / -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.sys. -'@ + [Rudder.Datastate]::Render('{{' + @' +'@ + [Rudder.Datastate]::Render('{{&' + @' vars.host '@ + '}}') + '}}')) + @' ' '' ''' $ $$ " "" \ \\😋aà3 diff --git a/policies/rudderc/tests/cases/general/ntp/technique.ps1 b/policies/rudderc/tests/cases/general/ntp/technique.ps1 index b830d42b106..5b082d7aee3 100644 --- a/policies/rudderc/tests/cases/general/ntp/technique.ps1 +++ b/policies/rudderc/tests/cases/general/ntp/technique.ps1 @@ -82,7 +82,7 @@ htop try { $componentKey = @' /bin/true "# -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.node.inventory.os.fullName '@ + '}}')) + @' " @@ -102,7 +102,7 @@ vars.node.inventory.os.fullName $methodParams = @{ Name = @' /bin/true "# -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.node.inventory.os.fullName '@ + '}}')) + @' " diff --git a/policies/rudderc/tests/cases/general/param_in_condition/technique.ps1 b/policies/rudderc/tests/cases/general/param_in_condition/technique.ps1 index aad0b733f8b..344770bb318 100644 --- a/policies/rudderc/tests/cases/general/param_in_condition/technique.ps1 +++ b/policies/rudderc/tests/cases/general/param_in_condition/technique.ps1 @@ -29,7 +29,7 @@ try { $componentKey = @' /tmp/ -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.param_in_condition.file '@ + '}}')) $reportParams = @{ @@ -77,7 +77,7 @@ vars.param_in_condition.file $class = ([Rudder.Condition]::canonify(@' file_check_exists__tmp_ -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.param_in_condition.file '@ + '}}')) + @' _kept diff --git a/policies/rudderc/tests/cases/general/variables/technique.ps1 b/policies/rudderc/tests/cases/general/variables/technique.ps1 index 2547310b07d..41228743c4f 100644 --- a/policies/rudderc/tests/cases/general/variables/technique.ps1 +++ b/policies/rudderc/tests/cases/general/variables/technique.ps1 @@ -47,25 +47,25 @@ true foo foobar # With parameter foo -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.test_windows.content '@ + '}}')) + @' foobar # With a var looking like a parameter foo -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.contentbis '@ + '}}')) + @' # With a const -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.const.n '@ + '}}')) + @' # With node properties -'@ + ([Rudder.Datastate]::Render('{{' + @' +'@ + ([Rudder.Datastate]::Render('{{&' + @' vars.node.properties.name.key '@ + '}}')) Path = @'