Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from ncharles/ust_7856/use_a_mustache_templat…
…e_from_a_string Fixes #7856: Use a mustache template from a string
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
##################################################################################### | ||
# Copyright 2016 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 File from a mustache string | ||
# @description This is a bundle to build a file from a mustache string | ||
# @agent_version >=3.7 | ||
# | ||
# @parameter template String containing a template to be expanded | ||
# @parameter destination Destination file | ||
# | ||
# @class_prefix file_from_string_mustache | ||
# @class_parameter destination | ||
# This bundle will define a class file_from_string_mustache_${destination}_{kept,repaired,not_ok,ok,reached} | ||
|
||
bundle agent file_from_string_mustache(template, destination) | ||
{ | ||
vars: | ||
"old_class_prefix" string => canonify("file_from_string_mustache_${destination}"); | ||
"promisers" slist => { @{this.callers_promisers}, cf_null }, policy => "ifdefined"; | ||
"class_prefix" string => canonify(join("_", "promisers")); | ||
"args" slist => { "${template}", "${destination}" }; | ||
"content" string => string_mustache("${template}", datastate()); | ||
|
||
files: | ||
"${destination}" | ||
create => "true", | ||
edit_line => insert_lines("${content}"), | ||
edit_defaults => ncf_empty_select("true"), | ||
classes => classes_generic_two("${old_class_prefix}", "${class_prefix}"); | ||
|
||
methods: | ||
any:: | ||
"report" usebundle => _log("Build file ${destination} from string template", "${old_class_prefix}", "${class_prefix}", @{args}); | ||
} |