Project

General

Profile

Actions

Bug #19199

closed

Techniques using a condition containing a variable are not canonified correctly with dsc agent

Added by Félix DALLIDET over 3 years ago. Updated over 3 years ago.

Status:
Released
Priority:
N/A
Category:
Web - Technique editor
Target version:
Severity:
UX impact:
User visibility:
Effort required:
Priority:
0
Name check:
To do
Fix check:
Checked
Regression:

Description

When creating a technique, if you use a condition based on a variable content, it will not canonify its value, leading to malformed conditions.
The logic should already be written since on the CfEngine technique side it is properly canonified.

We currently generate something like:

function Test-Technique {
  [CmdletBinding()]
  param (
      [parameter(Mandatory=$true)]
      [string]$reportId,
      [parameter(Mandatory=$true)]
      [string]$techniqueName,
      [parameter(Mandatory=$true)]
      [string]$File,
      [switch]$auditOnly
  )

  $local_classes = New-ClassContext
  $resources_dir = $PSScriptRoot + "\resources" 

  $local_classes = Merge-ClassContext $local_classes $(File-Content -File "${file}" -Lines "my_content" -Enforce "true" -componentName "File content" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly).get_item("classes")

  $class = "any.(file_lines_present_${file}_repaired)" 
  if (Evaluate-Class $class $local_classes $system_classes) {
    $local_classes = Merge-ClassContext $local_classes $(File-Content -File "C:\result.txt" -Lines "un peu de contenu
sur
plusieurs lignes" -Enforce "true" -componentName "File content" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly).get_item("classes")
  } else {
    _rudder_common_report_na -componentName "File content" -componentKey "C:\result.txt" -message "Not applicable" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly
  }

}

And we want something like:

function Test-Technique {
  [CmdletBinding()]
  param (
      [parameter(Mandatory=$true)]
      [string]$reportId,
      [parameter(Mandatory=$true)]
      [string]$techniqueName,
      [parameter(Mandatory=$true)]
      [string]$File,
      [switch]$auditOnly
  )

  $local_classes = New-ClassContext
  $resources_dir = $PSScriptRoot + "\resources" 

  $local_classes = Merge-ClassContext $local_classes $(File-Content -File "${file}" -Lines "my_content" -Enforce "true" -componentName "File content" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly).get_item("classes")

  $class = "any.(file_lines_present_" + $(Canonify-Class $file) + "_repaired)" 
  if (Evaluate-Class $class $local_classes $system_classes) {
    $local_classes = Merge-ClassContext $local_classes $(File-Content -File "C:\result.txt" -Lines "un peu de contenu
sur
plusieurs lignes" -Enforce "true" -componentName "File content" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly).get_item("classes")
  } else {
    _rudder_common_report_na -componentName "File content" -componentKey "C:\result.txt" -message "Not applicable" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly
  }

}

The diff is on the lines:

$class = "any.(file_lines_present_${file}_repaired)" 

and

$class = "any.(file_lines_present_" + $(Canonify-Class $file) + "_repaired)" 
Actions

Also available in: Atom PDF