Skip to content
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
37 changes: 37 additions & 0 deletions examples/classfilterdata_object_of_arrays.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#+begin_src cfengine3
bundle agent __main__
{
classes:
"role_2";

vars:
"original"
data => '{
"alice": [ "role_1", 32 ],
"bob": [ "!role_1", 24 ],
"malcom": [ "role_2", 27 ]
}';

"filtered"
data => classfilterdata("original", "object_of_arrays", "0");

reports:
"Filtered data: $(with)"
with => storejson("filtered");
}
#+end_src

#+begin_src example_output
#@ ```
#@ R: Filtered data: {
#@ "bob": [
#@ "!role_1",
#@ 24
#@ ],
#@ "malcom": [
#@ "role_2",
#@ 27
#@ ]
#@ }
#@ ```
#+end_src
38 changes: 38 additions & 0 deletions examples/classfilterdata_object_of_arrays_key_to_obj.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#+begin_src cfengine3
bundle agent __main__
{
classes:
"role_2";

vars:
"original"
data => '{
"role_1" : [ "alice", 32 ],
"!role_1" : [ "bob", 24 ],
"role_2" : [ "malcom", 27 ]
}';

# Using exogenous key (i.e., the key of the child array within the parent object)
"filtered"
data => classfilterdata("original", "object_of_arrays");

reports:
"Filtered data: $(with)"
with => storejson("filtered");
}
#+end_src

#+begin_src example_output
#@ ```
#@ R: Filtered data: {
#@ "!role_1": [
#@ "bob",
#@ 24
#@ ],
#@ "role_2": [
#@ "malcom",
#@ 27
#@ ]
#@ }
#@ ```
#+end_src
35 changes: 35 additions & 0 deletions examples/classfilterdata_object_of_objects.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#+begin_src cfengine3
bundle agent __main__
{
classes:
"role_2";

vars:
"original"
data => '{
"/tmp/foo": { "ifvarclass": "role_1" },
"/tmp/bar": { "ifvarclass": "role_2" },
"/tmp/baz": { "ifvarclass": "(role_1|role_2)" }
}';

"filtered"
data => classfilterdata("original", "object_of_objects", "ifvarclass");

reports:
"Filtered data: $(with)"
with => storejson("filtered");
}
#+end_src

#+begin_src example_output
#@ ```
#@ R: Filtered data: {
#@ "/tmp/bar": {
#@ "ifvarclass": "role_2"
#@ },
#@ "/tmp/baz": {
#@ "ifvarclass": "(role_1|role_2)"
#@ }
#@ }
#@ ```
#+end_src
36 changes: 36 additions & 0 deletions examples/classfilterdata_object_of_objects_key_to_obj.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#+begin_src cfengine3
bundle agent __main__
{
classes:
"role_2";

vars:
"original"
data => '{
"role_1": { "file": "/tmp/foo" },
"role_2": { "file": "/tmp/bar" },
"(role_1|role_2)": { "file": "/tmp/baz" }
}';

# Using exogenous key (i.e., the key of the child object within the parent object)
"filtered"
data => classfilterdata("original", "object_of_objects");

reports:
"Filtered data: $(with)"
with => storejson("filtered");
}
#+end_src

#+begin_src example_output
#@ ```
#@ R: Filtered data: {
#@ "(role_1|role_2)": {
#@ "file": "/tmp/baz"
#@ },
#@ "role_2": {
#@ "file": "/tmp/bar"
#@ }
#@ }
#@ ```
#+end_src
Loading
Loading