Project

General

Profile

« Previous | Next » 

Revision 46774242

Added by Félix DALLIDET over 6 years ago

Fixes #11317: Add a dsc version of file_template technique

View differences:

techniques/fileDistribution/fileTemplate/1.0/fileTemplate.ps1.st
function fileTemplate {
[CmdletBinding()]
param (
[parameter(Mandatory=$true)] [string]$reportId,
[parameter(Mandatory=$true)] [string]$techniqueName,
[switch]$auditOnly
)
$trackingkey = @(
&TRACKINGKEY:{directiveId |
"&directiveId&" };separator=","& )
$sources = @(
&FILE_TEMPLATE_TEMPLATE:{source |
"&source&" };separator=","& )
$isRaws = @(
&FILE_TEMPLATE_RAW_OR_NOT:{isRaw |
"&isRaw&" };separator=","& )
$rawSources = @(
&FILE_TEMPLATE_RAW_TEMPLATE:{rawSource |
"&rawSource&" };separator=","& )
$destinations = @(
&FILE_TEMPLATE_AGENT_DESTINATION_PATH:{destination |
"&destination&" };separator=","& )
$posthooks = @(
&FILE_TEMPLATE_TEMPLATE_POST_HOOK_COMMAND:{destination |
"&destination&" };separator=","& )
$HashCheckType = "sha256"
$local_classes = New-ClassContext
for ($i=0; $i -lt $trackingkey.length; $i++) {
$destinationsCanon = Canonify-Class($destinations[$i])
$templatesFolder = "C:\Program Files\Rudder\tmp\templates"
$templateDestinations = "${templatesFolder}\${destinationsCanon}"
$componentName = "Templates location"
#Check for templates folder
$local_classes = Merge-ClassContext $local_classes $(Directory-Create -target $templatesFolder -ReportId $trackingkey[$i] -componentName $componentName -componentKey $destinations[$i] -TechniqueName $techniqueName -auditOnly:$auditOnly -Report:$true)
#No need to check for permissions, they are well defined by the inheritence of Rudder folder
if ($isRaws[$i] -eq "Raw") {
#First, write the input in a file
$componentName = "Load Template from a file or text input"
$local_classes = Merge-ClassContext $local_classes $(File-Enforce-Content -File $templateDestinations -Lines $rawSources[$i] -ReportId $trackingkey[$i] -Enforce $true -componentName $componentName -componentKey $destinations[$i] -TechniqueName $techniqueName -auditOnly:$auditOnly -Report:$true)
} else {
#First, get the template from the server
$componentName = "Load Template from a file or text input"
$local_classes = Merge-ClassContext $local_classes $(File-From-Shared-Folder -Source $sources[$i] -Destination $templateDestinations -HashType $HashCheckType -ReportId $trackingkey[$i] -TechniqueName $techniqueName -componentName $componentName -componentKey $destinations[$i] -auditOnly:$auditOnly -Report:$true)
}
$componentName = "Expand template"
#Expand the template
$local_classes = Merge-ClassContext $local_classes $(File-From-Template-Mustache -SourceTemplate $templateDestinations -Destination $destinations[$i] -ReportId $trackingkey[$i] -TechniqueName $techniqueName -componentName $componentName -componentKey $destinations[$i] -auditOnly:$auditOnly -Report:$true)
#Posthook execution
$class_prefix = "file_from_template_${destinationsCanon}_repaired"
$componentName = "Posthook"
if ($posthooks[$i] -ne "" -And $local_classes["classes"].contains($class_prefix)) {
$local_classes = Merge-ClassContext $local_classes $(Command-Execution -CommandName $posthooks[$i] -ComponentKey $destinations[$i] -ComponentName $componentName -Report:$true -auditOnly:$auditOnly)
} else {
if ($auditOnly) { $state = [ComplianceStatus]::audit_na } else { $state = [ComplianceStatus]::result_na }
if ($posthooks[$i] -eq "") {
$PostHookString = "No posthook defined"
} else {
$PostHookString = "No posthook execution needed"
}
$classes = _rudder_common_report -TechniqueName $techniqueName -Status $state -ReportId $reportId -ComponentName $componentName -ComponentKey $destinations[$i] -Message $PostHookString -report:$true
}
#Sections non applicables
$state = if ($auditOnly) { [ComplianceStatus]::audit_na } else { [ComplianceStatus]::result_na }
$StringNa = "Not applicable"
$componentName = "Put permissions"
$classes = _rudder_common_report -TechniqueName $techniqueName -Status $state -ReportId $reportId -ComponentName $componentName -ComponentKey $destinations[$i] -Message $StringNa -report:$true
$componentName = "Templates directory permissions"
$classes = _rudder_common_report -TechniqueName $techniqueName -Status $state -ReportId $reportId -ComponentName $componentName -ComponentKey $destinations[$i] -Message $StringNa -report:$true
}
}
techniques/fileDistribution/fileTemplate/1.0/metadata.xml
</DESCRIPTION>
<MULTIINSTANCE>true</MULTIINSTANCE>
<TMLS>
<TML name="fileTemplate"/>
</TMLS>
<BUNDLES>
<NAME>fileTemplate</NAME>
</BUNDLES>
<AGENT type="dsc">
<BUNDLES>
<NAME>fileTemplate</NAME>
</BUNDLES>
<TMLS>
<TML name="fileTemplate.ps1">
<OUTPATH>fileTemplate/1.0/fileTemplate.ps1</OUTPATH>
</TML>
</TMLS>
</AGENT>
<AGENT type="cfengine-community">
<BUNDLES>
<NAME>fileTemplate</NAME>
</BUNDLES>
<TMLS>
<TML name="fileTemplate"/>
</TMLS>
</AGENT>
<TRACKINGVARIABLE>
<SAMESIZEAS>FILE_TEMPLATE_AGENT_DESTINATION_PATH</SAMESIZEAS>
......
</CONSTRAINT>
</INPUT>
<SELECT1>
<NAME>FILE_TEMPLATE_TEMPLATE_TYPE</NAME>
<DESCRIPTION>Template type</DESCRIPTION>
<ITEM>
<VALUE>mustache</VALUE>
<LABEL>mustache</LABEL>
</ITEM>
<ITEM>
<VALUE>jinja2</VALUE>
<LABEL>jinja2</LABEL>
</ITEM>
<CONSTRAINT>
<DEFAULT>mustache</DEFAULT>
</CONSTRAINT>
</SELECT1>
<INPUT>
<NAME>FILE_TEMPLATE_OWNER</NAME>
<DESCRIPTION>File owner</DESCRIPTION>
<CONSTRAINT>
<DEFAULT>root</DEFAULT>
<MAYBEEMPTY>false</MAYBEEMPTY>
<TYPE>string</TYPE>
</CONSTRAINT>
</INPUT>
<SECTION name="UNIX specific options" multivalued="false" component="false">
<SELECT1>
<NAME>FILE_TEMPLATE_TEMPLATE_TYPE</NAME>
<DESCRIPTION>Template type</DESCRIPTION>
<ITEM>
<VALUE>mustache</VALUE>
<LABEL>mustache</LABEL>
</ITEM>
<ITEM>
<VALUE>jinja2</VALUE>
<LABEL>jinja2</LABEL>
</ITEM>
<INPUT>
<NAME>FILE_TEMPLATE_GROUP_OWNER</NAME>
<DESCRIPTION>File group</DESCRIPTION>
<CONSTRAINT>
<DEFAULT>root</DEFAULT>
<MAYBEEMPTY>false</MAYBEEMPTY>
<TYPE>string</TYPE>
</CONSTRAINT>
</INPUT>
<CONSTRAINT>
<DEFAULT>mustache</DEFAULT>
</CONSTRAINT>
</SELECT1>
<INPUT>
<NAME>FILE_TEMPLATE_PERMISSIONS</NAME>
<DESCRIPTION>File mode</DESCRIPTION>
<CONSTRAINT>
<MAYBEEMPTY>false</MAYBEEMPTY>
<DEFAULT>700</DEFAULT>
<TYPE>perm</TYPE>
</CONSTRAINT>
</INPUT>
<INPUT>
<NAME>FILE_TEMPLATE_OWNER</NAME>
<DESCRIPTION>File owner</DESCRIPTION>
<CONSTRAINT>
<DEFAULT>root</DEFAULT>
<MAYBEEMPTY>false</MAYBEEMPTY>
<TYPE>string</TYPE>
</CONSTRAINT>
</INPUT>
<INPUT>
<NAME>FILE_TEMPLATE_TEMPLATE_POST_HOOK_COMMAND</NAME>
<DESCRIPTION>Command(s) to run after any modification made on the destination file</DESCRIPTION>
<LONGDESCRIPTION>List of shell-compatible statements to be executed. Multiple commands may be specified on separate lines.</LONGDESCRIPTION>
<CONSTRAINT>
<MAYBEEMPTY>true</MAYBEEMPTY>
<TYPE>string</TYPE>
</CONSTRAINT>
</INPUT>
<INPUT>
<NAME>FILE_TEMPLATE_GROUP_OWNER</NAME>
<DESCRIPTION>File group</DESCRIPTION>
<CONSTRAINT>
<DEFAULT>root</DEFAULT>
<MAYBEEMPTY>false</MAYBEEMPTY>
<TYPE>string</TYPE>
</CONSTRAINT>
</INPUT>
<SELECT1>
<NAME>FILE_TEMPLATE_PERSISTENT_POST_HOOK</NAME>
<DESCRIPTION>Retry hook on error</DESCRIPTION>
<ITEM>
<VALUE>true</VALUE>
<LABEL>Yes</LABEL>
</ITEM>
<ITEM>
<VALUE>false</VALUE>
<LABEL>False</LABEL>
</ITEM>
<INPUT>
<NAME>FILE_TEMPLATE_PERMISSIONS</NAME>
<DESCRIPTION>File mode</DESCRIPTION>
<CONSTRAINT>
<MAYBEEMPTY>false</MAYBEEMPTY>
<DEFAULT>700</DEFAULT>
<TYPE>perm</TYPE>
</CONSTRAINT>
</INPUT>
<SELECT1>
<NAME>FILE_TEMPLATE_PERSISTENT_POST_HOOK</NAME>
<DESCRIPTION>Retry hook on error</DESCRIPTION>
<ITEM>
<VALUE>true</VALUE>
<LABEL>Yes</LABEL>
</ITEM>
<ITEM>
<VALUE>false</VALUE>
<LABEL>False</LABEL>
</ITEM>
<CONSTRAINT>
<DEFAULT>true</DEFAULT>
<MAYBEEMPTY>false</MAYBEEMPTY>
</CONSTRAINT>
</SELECT1>
<CONSTRAINT>
<DEFAULT>true</DEFAULT>
<MAYBEEMPTY>false</MAYBEEMPTY>
</CONSTRAINT>
</SELECT1>
</SECTION>
<SECTION name="Expand template" multivalued="false" component="true" componentKey="FILE_TEMPLATE_AGENT_DESTINATION_PATH">
</SECTION>
......
</SECTION>
<SECTION name="Posthook" multivalued="false" component="true" componentKey="FILE_TEMPLATE_AGENT_DESTINATION_PATH">
<INPUT>
<NAME>FILE_TEMPLATE_TEMPLATE_POST_HOOK_COMMAND</NAME>
<DESCRIPTION>Command(s) to run after any modification made on the destination file</DESCRIPTION>
<LONGDESCRIPTION>List of shell-compatible statements to be executed. Multiple commands may be specified on separate lines.</LONGDESCRIPTION>
<CONSTRAINT>
<MAYBEEMPTY>true</MAYBEEMPTY>
<TYPE>string</TYPE>
</CONSTRAINT>
</INPUT>
</SECTION>
<SECTION name="Templates location" multivalued="false" component="true" componentKey="FILE_TEMPLATE_AGENT_DESTINATION_PATH">

Also available in: Unified diff