diff --git a/policies/rudderc/src/backends/windows.rs b/policies/rudderc/src/backends/windows.rs index 15a35188089..90f40487f3b 100644 --- a/policies/rudderc/src/backends/windows.rs +++ b/policies/rudderc/src/backends/windows.rs @@ -49,7 +49,7 @@ struct TechniqueTemplate<'a> { } /// Filters for the technique template -mod filters { +pub mod filters { use std::fmt::Display; use anyhow::Error; @@ -84,7 +84,7 @@ mod filters { } /// `my_method` -> `MyMethod` - pub fn _camel_case(s: T) -> askama::Result { + pub fn camel_case(s: T) -> askama::Result { Ok(s.to_string() .split('_') .map(uppercase_first_letter) @@ -176,7 +176,7 @@ fn method_call(m: Method, condition: Condition) -> Result { Some(condition.to_string()) }, args, - name: Windows::pascal_case(&m.info.as_ref().unwrap().bundle_name), + name: filters::dsc_case(&m.info.as_ref().unwrap().bundle_name).unwrap(), }) } @@ -185,33 +185,8 @@ impl Windows { Self } - fn pascal_case(s: &str) -> String { - let chars = s.chars(); - - let mut pascal = String::new(); - let mut is_next_uppercase = true; - for c in chars { - let next = match c { - ' ' | '_' | '-' => { - is_next_uppercase = true; - String::new() - } - c => { - if is_next_uppercase { - is_next_uppercase = false; - c.to_uppercase().to_string() - } else { - c.to_string() - } - } - }; - pascal.push_str(&next); - } - pascal - } - pub fn technique_name(s: &str) -> String { - Self::pascal_case(s) + filters::dsc_case(s).unwrap() } fn technique(src: Technique, resources: &Path) -> Result { diff --git a/policies/rudderc/templates/technique.ps1.askama b/policies/rudderc/templates/technique.ps1.askama index aa0921c98ea..93d2f78d012 100644 --- a/policies/rudderc/templates/technique.ps1.askama +++ b/policies/rudderc/templates/technique.ps1.askama @@ -34,7 +34,7 @@ function {{ id|dsc_case }} { ComponentName = "{{ m.component_name|escape_double_quotes }}" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = {{ m.disable_reporting }} + DisableReporting = ${{ m.disable_reporting }} TechniqueName = $techniqueName } {% match m.condition %} @@ -46,7 +46,7 @@ function {{ id|dsc_case }} { {{- arg.0|dsc_case }} = {{ arg|parameter_fmt }} {% endfor %} } - $call = {{ m.name|dsc_case }} $methodParams -PolicyMode $policyMode + $call = {{ m.name|dsc_case }} @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) } else { @@ -58,7 +58,7 @@ function {{ id|dsc_case }} { {{- arg.0|dsc_case }} = "{{ arg.1 }}" {% endfor %} } - $call = {{ m.name }} $methodParams -PolicyMode $policyMode + $call = {{ m.name }} @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) {% endmatch %} diff --git a/policies/rudderc/tests/cases/general/escaping/technique.ps1 b/policies/rudderc/tests/cases/general/escaping/technique.ps1 index 31f0ef94ddc..c52c26e7efc 100644 --- a/policies/rudderc/tests/cases/general/escaping/technique.ps1 +++ b/policies/rudderc/tests/cases/general/escaping/technique.ps1 @@ -29,7 +29,7 @@ ComponentName = "${sys.host} . | / ${sys.${host}} ' '' ''' $ $$ `" `"`" \ \\😋aà3" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -44,7 +44,7 @@ '@ } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) } else { diff --git a/policies/rudderc/tests/cases/general/form/technique.ps1 b/policies/rudderc/tests/cases/general/form/technique.ps1 index 7758947dd12..4d9ea9c093b 100644 --- a/policies/rudderc/tests/cases/general/form/technique.ps1 +++ b/policies/rudderc/tests/cases/general/form/technique.ps1 @@ -68,7 +68,7 @@ ComponentName = "Ensure correct ntp configuration" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -83,7 +83,7 @@ '@ } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) } else { diff --git a/policies/rudderc/tests/cases/general/min/technique.ps1 b/policies/rudderc/tests/cases/general/min/technique.ps1 index fc1768affb0..0cf1dd50580 100644 --- a/policies/rudderc/tests/cases/general/min/technique.ps1 +++ b/policies/rudderc/tests/cases/general/min/technique.ps1 @@ -26,7 +26,7 @@ ComponentName = "Package present" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -37,7 +37,7 @@ Version = "2.3.4" } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) diff --git a/policies/rudderc/tests/cases/general/ntp/metadata.xml b/policies/rudderc/tests/cases/general/ntp/metadata.xml index 6e98025ebfc..60cf7635eb6 100644 --- a/policies/rudderc/tests/cases/general/ntp/metadata.xml +++ b/policies/rudderc/tests/cases/general/ntp/metadata.xml @@ -5,7 +5,7 @@ separated-with-parameters - ntp + ntp_technique @@ -13,13 +13,13 @@ false - ntp/0.1/resources/file.cfg + ntp_technique/0.1/resources/file.cfg - Ntp + Ntp-Technique @@ -27,7 +27,7 @@ false - ntp/0.1/resources/file.cfg + ntp_technique/0.1/resources/file.cfg diff --git a/policies/rudderc/tests/cases/general/ntp/technique.cf b/policies/rudderc/tests/cases/general/ntp/technique.cf index fa455cbb424..95ac4cb86d1 100644 --- a/policies/rudderc/tests/cases/general/ntp/technique.cf +++ b/policies/rudderc/tests/cases/general/ntp/technique.cf @@ -1,14 +1,14 @@ # @name NTP # @version 0.1 -bundle agent ntp(server) { +bundle agent ntp_technique(server) { vars: "resources_dir" string => "${this.promise_dirname}/resources"; "args" slist => {"${server}"}; "report_param" string => join("_", args); - "full_class_prefix" string => canonify("ntp_${report_param}"); + "full_class_prefix" string => canonify("ntp_technique_${report_param}"); "class_prefix" string => string_head("${full_class_prefix}", "1000"); methods: diff --git a/policies/rudderc/tests/cases/general/ntp/technique.ps1 b/policies/rudderc/tests/cases/general/ntp/technique.ps1 index 9929eca8393..9e53160ca32 100644 --- a/policies/rudderc/tests/cases/general/ntp/technique.ps1 +++ b/policies/rudderc/tests/cases/general/ntp/technique.ps1 @@ -1,4 +1,4 @@ -function Ntp { +function Ntp-Technique { [CmdletBinding()] param ( [parameter(Mandatory = $true)] @@ -31,7 +31,7 @@ ComponentName = "Ensure correct ntp configuration" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -46,7 +46,7 @@ '@ } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) } else { @@ -61,7 +61,7 @@ ComponentName = "NTP service" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -71,7 +71,7 @@ Name = "/bin/true `"# $($node.inventory[os][fullName])`"" } - $call = PackageInstall $methodParams -PolicyMode $policyMode + $call = Package-Install @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) } else { diff --git a/policies/rudderc/tests/cases/general/ntp/technique.yml b/policies/rudderc/tests/cases/general/ntp/technique.yml index db8001e74c5..fe27221de62 100644 --- a/policies/rudderc/tests/cases/general/ntp/technique.yml +++ b/policies/rudderc/tests/cases/general/ntp/technique.yml @@ -1,5 +1,5 @@ --- -id: ntp +id: ntp_technique name: NTP version: "0.1" params: diff --git a/policies/rudderc/tests/cases/general/reporting/technique.ps1 b/policies/rudderc/tests/cases/general/reporting/technique.ps1 index 64fcadf94ec..7a7e8d3ac1c 100644 --- a/policies/rudderc/tests/cases/general/reporting/technique.ps1 +++ b/policies/rudderc/tests/cases/general/reporting/technique.ps1 @@ -26,7 +26,7 @@ ComponentName = "No block without condition" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -37,7 +37,7 @@ Version = "" } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) @@ -50,7 +50,7 @@ ComponentName = "No block with condition" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -65,7 +65,7 @@ '@ } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) } else { @@ -80,7 +80,7 @@ ComponentName = "NTP service" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -91,7 +91,7 @@ Version = "" } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) @@ -104,7 +104,7 @@ ComponentName = "NTP service" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -115,7 +115,7 @@ Version = "" } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) @@ -128,7 +128,7 @@ ComponentName = "NTP service" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -139,7 +139,7 @@ Version = "" } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) @@ -152,7 +152,7 @@ ComponentName = "NTP service" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -163,7 +163,7 @@ Version = "" } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) @@ -176,7 +176,7 @@ ComponentName = "Enabled reporting" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = false + DisableReporting = $false TechniqueName = $techniqueName } @@ -187,7 +187,7 @@ Version = "" } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) @@ -200,7 +200,7 @@ ComponentName = "Disabled reporting" PolicyMode = $policyMode ReportId = $reportId - DisableReporting = true + DisableReporting = $true TechniqueName = $techniqueName } @@ -211,7 +211,7 @@ Version = "" } - $call = PackagePresent $methodParams -PolicyMode $policyMode + $call = Package-Present @methodParams -PolicyMode $policyMode $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext)