Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENT-10793: Added rendering of custom mustache templates to $(sys.workdir)/modules #2747

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cfe_internal/update/update_policy.cf
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,9 @@ bundle agent modules_presence
vars:
"_vendored_dir" string => "$(this.promise_dirname)/../../modules/packages/vendored/";
"_override_dir" string => "$(this.promise_dirname)/../../modules/packages/";
"_custom_template_dir" string => "$(this.promise_dirname)/../../modules/mustache/";
"_vendored_paths" slist => findfiles("$(_vendored_dir)*.mustache");
"_custom_template_paths" slist => findfiles("$(_custom_template_dir)*.mustache"), if => isdir( "$(_custom_template_dir)" );
"_package_paths" slist => filter("$(_override_dir)vendored", _package_paths_tmp, "false", "true", 999);
windows::
"_package_paths_tmp" slist => findfiles("\Q$(_override_dir)\E*");
Expand All @@ -811,7 +813,8 @@ bundle agent modules_presence
"_package_paths_tmp" slist => findfiles("$(_override_dir)*");
"_vendored_modules" slist => maplist(regex_replace("$(this)", "$(_vendored_dir)(.*).mustache", "$1", "g"), @(_vendored_paths));
"_override_modules" slist => maplist(regex_replace("$(this)", "$(_override_dir)(.*)", "$1", "g"), @(_package_paths));
"_not_vendored_modules_pathname_regex" string => "$(sys.inputdir)/modules/(?!packages/vendored).*";
"_custom_template_modules" slist => maplist(regex_replace("$(this)", "$(_custom_template_dir)(.*).mustache", "$1", "g"), @(_custom_template_paths));
"_not_vendored_modules_pathname_regex" string => "$(sys.inputdir)/modules/(?!(packages/vendored|mustache/)).*";

classes:
"override_vendored_module_$(_vendored_modules)" expression => fileexists("$(_override_dir)$(_vendored_modules)");
Expand All @@ -836,6 +839,14 @@ bundle agent modules_presence
canonify("override_vendored_module_$(_override_modules)"),
canonify("override_module_$(_override_modules)"));

"$(sys.workdir)/modules/$(_custom_template_modules)" -> { "ENT-10793" }
comment => "We want to render mustache templated modules",
handle => "cfe_internal_update_policy_files_custom_template_modules",
template_method => "mustache",
edit_template => "$(_custom_template_dir)$(_custom_template_modules).mustache",
perms => u_mo("500", "root"),
if => fileexists("$(_custom_template_dir)$(_custom_template_modules).mustache");

"$(sys.workdir)/modules"
comment => "Copy any non-packages modules",
handle => "cfe_internal_update_policy_files_nonpackages_modules",
Expand Down
11 changes: 11 additions & 0 deletions modules/mustache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Files in this directory ending in `.mustache` are rendered to
`$(sys.workdir)/modules` (typically `/var/cfengine/modules`) using `datastate()`
from the `update.cf` policy entry. Templates in sub-directories are not
considered.

For example `hello.sh.mustache` will be rendered to
`$(sys.workdir)/modules/hello.sh` and `sub-dir/goodbye.sh.mustache` would not be
rendered to `$(sys.workdir)/modules/sub-dir/goodby.sh`.

## History
- Added in 3.23.0