-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
218 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
policies/rudderc/tests/cases/general/long_method_param_name/metadata.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<TECHNIQUE name="Windows long param names"> | ||
<DESCRIPTION>Windows long param names</DESCRIPTION> | ||
<USEMETHODREPORTING>true</USEMETHODREPORTING> | ||
<MULTIINSTANCE>false</MULTIINSTANCE> | ||
<POLICYGENERATION>separated</POLICYGENERATION> | ||
<AGENT type="cfengine-community"> | ||
<BUNDLES> | ||
<NAME>Windows_long_param_names</NAME> | ||
</BUNDLES> | ||
<FILES> | ||
<FILE name="technique.cf"> | ||
<INCLUDED>true</INCLUDED> | ||
</FILE> | ||
</FILES> | ||
</AGENT> | ||
<AGENT type="dsc"> | ||
<BUNDLES> | ||
<NAME>Windows-Long-Param-Names</NAME> | ||
</BUNDLES> | ||
<FILES> | ||
<FILE name="technique.ps1"> | ||
<INCLUDED>true</INCLUDED> | ||
</FILE> | ||
</FILES> | ||
</AGENT> | ||
<SECTIONS> | ||
<SECTION name="Report if condition" id="d86ce2e5-d5b6-45cc-87e8-c11cca71d907" component="true" multivalued="true"> | ||
<REPORTKEYS> | ||
<VALUE id="d86ce2e5-d5b6-45cc-87e8-c11cca71d907"> | ||
This should be ReportMessage | ||
</VALUE> | ||
</REPORTKEYS> | ||
</SECTION> | ||
</SECTIONS> | ||
</TECHNIQUE> |
22 changes: 22 additions & 0 deletions
22
policies/rudderc/tests/cases/general/long_method_param_name/technique.cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# @name Windows long param names | ||
# @version 0.1 | ||
|
||
bundle agent Windows_long_param_names { | ||
|
||
vars: | ||
"args" slist => {}; | ||
"report_param" string => join("_", args); | ||
"full_class_prefix" string => canonify("Windows_long_param_names_${report_param}"); | ||
"class_prefix" string => string_head("${full_class_prefix}", "1000"); | ||
|
||
methods: | ||
"d86ce2e5-d5b6-45cc-87e8-c11cca71d907_${report_data.directive_id}" usebundle => call_d86ce2e5_d5b6_45cc_87e8_c11cca71d907("Report if condition", "This should be ReportMessage", "d86ce2e5-d5b6-45cc-87e8-c11cca71d907", @{args}, "${class_prefix}", "This should be ReportMessage", "it_generates_properly"); | ||
|
||
} | ||
bundle agent call_d86ce2e5_d5b6_45cc_87e8_c11cca71d907(c_name, c_key, report_id, args, class_prefix, report_message, condition) { | ||
|
||
methods: | ||
"d86ce2e5-d5b6-45cc-87e8-c11cca71d907_${report_data.directive_id}" usebundle => _method_reporting_context_v4("${c_name}", "${c_key}", "${report_id}"); | ||
"d86ce2e5-d5b6-45cc-87e8-c11cca71d907_${report_data.directive_id}" usebundle => report_if_condition("${report_message}", "${condition}"); | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
policies/rudderc/tests/cases/general/long_method_param_name/technique.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function Windows-Long-Param-Names { | ||
[CmdletBinding()] | ||
param ( | ||
[parameter(Mandatory = $true)] | ||
[string]$reportId, | ||
[parameter(Mandatory = $true)] | ||
[string]$techniqueName, | ||
|
||
[Rudder.PolicyMode]$policyMode | ||
) | ||
$techniqueParams = @{ | ||
|
||
} | ||
BeginTechniqueCall -Name $techniqueName -Parameters $techniqueParams | ||
$reportIdBase = $reportId.Substring(0, $reportId.Length - 1) | ||
$localContext = New-Object -TypeName "Rudder.Context" -ArgumentList @($techniqueName) | ||
$localContext.Merge($system_classes) | ||
|
||
|
||
|
||
$reportId=$reportIdBase + "d86ce2e5-d5b6-45cc-87e8-c11cca71d907" | ||
$componentKey = "This should be ReportMessage" | ||
$reportParams = @{ | ||
ClassPrefix = ([Rudder.Condition]::canonify(("report_if_condition_" + $componentKey))) | ||
ComponentKey = $componentKey | ||
ComponentName = "Report if condition" | ||
PolicyMode = $policyMode | ||
ReportId = $reportId | ||
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) | ||
|
||
|
||
|
||
EndTechniqueCall -Name $techniqueName | ||
} |
10 changes: 10 additions & 0 deletions
10
policies/rudderc/tests/cases/general/long_method_param_name/technique.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
id: Windows_long_param_names | ||
name: Windows long param names | ||
version: "0.1" | ||
items: | ||
- id: d86ce2e5-d5b6-45cc-87e8-c11cca71d907 | ||
method: report_if_condition | ||
params: | ||
condition: "it_generates_properly" | ||
report_message: "This should be ReportMessage" |
76 changes: 76 additions & 0 deletions
76
policies/rudderc/tests/lib/common/30_generic_methods/report_if_condition.cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
##################################################################################### | ||
# Copyright 2021 Normation SAS | ||
##################################################################################### | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, Version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
##################################################################################### | ||
|
||
# @name Report if condition | ||
# @description Report a Rudder report based on a condition. | ||
# @action | ||
# @documentation | ||
# | ||
# This method will only send a Rudder report: | ||
# | ||
# If the **condition** is met, it will report a compliant report, with the following message: | ||
# `**<report_message>** was correct.` | ||
# | ||
# Otherwise, it will report an error, with the following message: | ||
# `**report_message** was incorrect` | ||
# | ||
# This method will never be in a repaired state. | ||
# | ||
# @parameter report_message Message subject, will be extended based on the report status | ||
# @parameter condition Condition to report a success | ||
# | ||
# @class_prefix report_if_condition | ||
# @class_parameter report_message | ||
# @agent_support = ["cfengine-community"] | ||
|
||
bundle agent report_if_condition(report_message, condition) | ||
{ | ||
vars: | ||
"old_class_prefix" string => canonify("report_if_condition_${report_message}"); | ||
"args" slist => { "${report_message}", "${condition}" }; | ||
"report_param" string => join("_", args); | ||
"full_class_prefix" string => canonify("report_if_condition_${report_param}"); | ||
"class_prefix" string => string_head("${full_class_prefix}", "1000"); | ||
|
||
classes: | ||
"pass2" expression => "pass1"; | ||
"pass1" expression => "any"; | ||
"local_expression" expression => "${condition}"; | ||
|
||
methods: | ||
pass2:: | ||
"success old class class" usebundle => _classes_success("${old_class_prefix}"), | ||
if => "local_expression"; | ||
"success class prefix" usebundle => _classes_success("${class_prefix}"), | ||
if => "local_expression"; | ||
|
||
"error old class class" usebundle => _classes_failure("${old_class_prefix}"), | ||
if => not("local_expression"); | ||
"error class prefix" usebundle => _classes_failure("${class_prefix}"), | ||
if => not("local_expression"); | ||
|
||
"report" usebundle => _log_v3("${report_message}", "${report_message}", "${old_class_prefix}", "${class_prefix}", @{args}), | ||
if => "${old_class_prefix}_reached|${class_prefix}_reached"; | ||
reports: | ||
pass2.local_expression:: | ||
"Condition ${condition} evaluates to true"; | ||
pass2.!local_expression:: | ||
"Condition ${condition} evaluates to false"; | ||
|
||
} | ||
|