Skip to content

Commit

Permalink
Fixes #23581: Missing NA report on Windows for methods only compatibl…
Browse files Browse the repository at this point in the history
…e with Unix
  • Loading branch information
amousset committed Oct 16, 2023
1 parent 0b0284d commit 93b3d33
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
6 changes: 5 additions & 1 deletion policies/rudderc/src/backends/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -132,6 +132,7 @@ struct WindowsMethod {
condition: Option<String>,
args: Vec<(String, String, Escaping)>,
name: String,
is_supported: bool,
}

fn method_call(m: Method, condition: Condition) -> Result<WindowsMethod> {
Expand Down Expand Up @@ -164,6 +165,8 @@ fn method_call(m: Method, condition: Condition) -> Result<WindowsMethod> {
// 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(),
Expand All @@ -178,6 +181,7 @@ fn method_call(m: Method, condition: Condition) -> Result<WindowsMethod> {
},
args,
name: filters::dsc_case(&m.info.as_ref().unwrap().bundle_name).unwrap(),
is_supported,
})
}

Expand Down
4 changes: 4 additions & 0 deletions policies/rudderc/templates/technique.ps1.askama
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 93b3d33

Please sign in to comment.