From 93b3d33db75e39d0f2599c3400200f2969d77571 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Mon, 16 Oct 2023 16:46:20 +0200 Subject: [PATCH] Fixes #23581: Missing NA report on Windows for methods only compatible with Unix --- policies/rudderc/src/backends/windows.rs | 6 +++++- policies/rudderc/templates/technique.ps1.askama | 4 ++++ .../general/long_method_param_name/technique.ps1 | 11 +---------- .../lib/common/30_generic_methods/package_present.cf | 1 + .../lib/common/30_generic_methods/package_present.yml | 1 + 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/policies/rudderc/src/backends/windows.rs b/policies/rudderc/src/backends/windows.rs index 399d88955c3..ad0bc34ce02 100644 --- a/policies/rudderc/src/backends/windows.rs +++ b/policies/rudderc/src/backends/windows.rs @@ -5,7 +5,7 @@ use std::path::Path; use anyhow::{bail, Result}; use askama::Template; -use rudder_commons::Escaping; +use rudder_commons::{methods::method::Agent, Escaping}; use super::Backend; use crate::ir::{ @@ -132,6 +132,7 @@ struct WindowsMethod { condition: Option, args: Vec<(String, String, Escaping)>, name: String, + is_supported: bool, } fn method_call(m: Method, condition: Condition) -> Result { @@ -164,6 +165,8 @@ fn method_call(m: Method, condition: Condition) -> Result { // We want a stable output args.sort(); + let is_supported = m.info.unwrap().agent_support.contains(&Agent::Dsc); + Ok(WindowsMethod { id: m.id.to_string(), class_prefix: m.info.as_ref().unwrap().class_prefix.clone(), @@ -178,6 +181,7 @@ fn method_call(m: Method, condition: Condition) -> Result { }, args, name: filters::dsc_case(&m.info.as_ref().unwrap().bundle_name).unwrap(), + is_supported, }) } diff --git a/policies/rudderc/templates/technique.ps1.askama b/policies/rudderc/templates/technique.ps1.askama index 481123a4399..c0222026d17 100644 --- a/policies/rudderc/templates/technique.ps1.askama +++ b/policies/rudderc/templates/technique.ps1.askama @@ -37,6 +37,7 @@ function {{ id|dsc_case }} { DisableReporting = ${{ m.disable_reporting }} TechniqueName = $techniqueName } + {%- if m.is_supported %} {% match m.condition %} {%- when Some with (cond) %} $class = {{ cond|canonify_condition }} @@ -62,6 +63,9 @@ function {{ id|dsc_case }} { $methodContext = Compute-Method-Call @reportParams -MethodCall $call $localContext.merge($methodContext) {% endmatch %} + {%- else %} + Rudder-Report-NA @reportParams + {%- endif %} {% endfor %} EndTechniqueCall -Name $techniqueName diff --git a/policies/rudderc/tests/cases/general/long_method_param_name/technique.ps1 b/policies/rudderc/tests/cases/general/long_method_param_name/technique.ps1 index dd58cd17ccb..89fa66d7ece 100644 --- a/policies/rudderc/tests/cases/general/long_method_param_name/technique.ps1 +++ b/policies/rudderc/tests/cases/general/long_method_param_name/technique.ps1 @@ -29,16 +29,7 @@ DisableReporting = $false TechniqueName = $techniqueName } - - $methodParams = @{ - Condition = "it_generates_properly" - ReportMessage = "This should be ReportMessage" - - } - $call = Report-If-Condition @methodParams -PolicyMode $policyMode - $methodContext = Compute-Method-Call @reportParams -MethodCall $call - $localContext.merge($methodContext) - + Rudder-Report-NA @reportParams EndTechniqueCall -Name $techniqueName diff --git a/policies/rudderc/tests/lib/common/30_generic_methods/package_present.cf b/policies/rudderc/tests/lib/common/30_generic_methods/package_present.cf index ae3ef804786..78eacc4484f 100644 --- a/policies/rudderc/tests/lib/common/30_generic_methods/package_present.cf +++ b/policies/rudderc/tests/lib/common/30_generic_methods/package_present.cf @@ -33,6 +33,7 @@ # # @class_prefix package_present # @class_parameter name +# @agent_support = ["cfengine-community", "dsc"] # This line should be ignored bundle agent package_present(name, version, architecture, provider) diff --git a/policies/rudderc/tests/lib/common/30_generic_methods/package_present.yml b/policies/rudderc/tests/lib/common/30_generic_methods/package_present.yml index 7e67a494bd5..60de0d25211 100644 --- a/policies/rudderc/tests/lib/common/30_generic_methods/package_present.yml +++ b/policies/rudderc/tests/lib/common/30_generic_methods/package_present.yml @@ -13,6 +13,7 @@ bundle_args: - provider agent_support: - cfengine-community + - dsc parameter: - name: name description: "Name of the package, or path to a local package"