Skip to content

Commit 38a56f6

Browse files
authored
Merge pull request #1835 from nickanderson/CFE-3426/master
Added ability to extend known paths without modifying vendored policy
2 parents 6b9cef0 + 3d01600 commit 38a56f6

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

lib/paths.cf

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,48 @@ bundle common paths
2626
# }
2727
# ```
2828
#
29+
# The paths bundle can be extended with custom paths by tagging *classic array* variables with `paths.cf`.
30+
#
31+
# **Example:**
32+
#
33+
# ```cf3
34+
# bundle agent extended_paths_example
35+
# {
36+
# meta:
37+
# "tags" slist => { "autorun" };
38+
#
39+
# vars:
40+
# # NOTE: the key will be canonified when it's pulled in to the paths bundle.
41+
# "path[orange]" string => "/bin/true", meta => { "paths.cf" };
42+
# "path[true-blue]" string => "/bin/true", meta => { "paths.cf" };
43+
# "foo[bar]" string => "/bin/true", meta => { "paths.cf" };
44+
#
45+
# this_context_isnt_defined_so_no_path::
46+
# "path[red]" string => "/bin/true", meta => { "paths.cf" };
47+
#
48+
# reports:
49+
# _stdlib_path_exists_orange::
50+
# "path paths.orange == $(paths.orange)";
51+
# "path paths.path[orange] == $(paths.path[orange])";
52+
#
53+
# _stdlib_path_exists_bar::
54+
# "path paths.bar == $(paths.bar)";
55+
# "path paths.path[bar] == $(paths.path[bar])";
56+
#
57+
# _stdlib_path_exists_true_blue::
58+
# "path paths.true_blue == $(paths.true_blue)";
59+
# "path paths.path[true_blue] == $(paths.path[true_blue])";
60+
#
61+
# _stdlib_path_exists_red::
62+
# "path paths.red == $(paths.red)";
63+
# "path paths.path[red] == $(paths.path[red])";
64+
#
65+
# !_stdlib_path_exists_red::
66+
# "path paths.red was not found";
67+
# "path paths.path[red] was not found";
68+
# }
69+
# ```
70+
#
2971
# Additionally several path entries are present to aid in policy sharing between
3072
# unix systems and Android Termux environments.
3173
#
@@ -41,6 +83,10 @@ bundle common paths
4183
# ```
4284
#
4385
# In case of termux, `paths.etc_path` will be `/data/data/com.termux/files/usr/etc`.
86+
#
87+
# **History:**
88+
#
89+
# - Ability to extend paths by tagging classic array variables added 3.17.0 (works with binary version 3.11.0 and greater)
4490
{
4591
vars:
4692

@@ -613,6 +659,16 @@ bundle common paths
613659
"var_path" string => "/var";
614660

615661
any::
662+
@if minimum_version(3.11.0)
663+
# Pull in variables tagged with `paths.cf`
664+
"_extended_path_data" -> { "CFE-3426" }
665+
data => variablesmatching_as_data( ".*", "paths.cf" );
666+
"_i" -> { "CFE-3426" }
667+
slist => getindices( _extended_path_data );
668+
"path[$(with)]" -> { "CFE-3426" }
669+
string => "$(_extended_path_data[$(_i)])",
670+
with => canonify( regex_replace( $(_i), ".*\[(.*)\]", "$1", "") );
671+
@endif
616672

617673
"all_paths" slist => getindices("path");
618674
"$(all_paths)" string => "$(path[$(all_paths)])";

0 commit comments

Comments
 (0)