Skip to content

Commit ce392f7

Browse files
committed
Formatted recently introduced examples according to style guide
I noticed some inconsistencies in our recently published examples from docs, so made some adjustments. Policy style guide: https://docs.cfengine.com/docs/3.24/examples-tutorials-writing-and-serving-policy-policy-style.html Signed-off-by: Ole Herman Schumacher Elgesem <ole@northern.tech>
1 parent 7e48480 commit ce392f7

File tree

6 files changed

+68
-75
lines changed

6 files changed

+68
-75
lines changed

examples/findlocalusers.cf

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
#+begin_src cfengine3
22
body common control
33
{
4-
bundlesequence => { "example" };
4+
bundlesequence => { "example" };
55
}
6+
67
bundle agent example
78
{
8-
vars:
9-
"root_filter" slist => {"gid=0", "name=root"};
10-
"root_container" data => findlocalusers("@(root_filter)");
11-
"root_list" slist => getindices("root_container");
12-
13-
"bin_filter" data => '["name=bin"]';
14-
"bin_container" data => findlocalusers("@(bin_filter)");
15-
"bin_list" slist => getindices("bin_container");
9+
vars:
10+
"root_filter"
11+
slist => {"gid=0", "name=root"};
12+
"root_container"
13+
data => findlocalusers("@(root_filter)");
14+
"root_list"
15+
slist => getindices("root_container");
16+
"bin_filter"
17+
data => '["name=bin"]';
18+
"bin_container"
19+
data => findlocalusers("@(bin_filter)");
20+
"bin_list"
21+
slist => getindices("bin_container");
1622

17-
reports:
18-
"List: $(root_list)";
19-
"List: $(bin_list)";
23+
reports:
24+
"List: $(root_list)";
25+
"List: $(bin_list)";
2026
}
2127

2228
#+end_src

examples/getbundlemetatags.cf

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
#+begin_src cfengine3
22
body common control
33
{
4-
bundlesequence => { "example" };
4+
bundlesequence => { "example" };
55
}
66

77
bundle agent example
88
{
99
meta:
10-
"tags" slist => { "autorun", "myOtherTag", "contact=Some Person <some.person@northern.tech>"};
10+
"tags"
11+
slist => {
12+
"autorun",
13+
"myOtherTag",
14+
"contact=Some Person <some.person@northern.tech>",
15+
};
1116

1217
vars:
13-
"bundle_tags" slist => getbundlemetatags("default:example");
14-
"contact_tag" slist => getbundlemetatags("default:example", "contact");
18+
"bundle_tags"
19+
slist => getbundlemetatags("default:example");
20+
"contact_tag"
21+
slist => getbundlemetatags("default:example", "contact");
1522

1623
reports:
17-
"Found tags: $(bundle_tags)";
18-
"Contact tag: $(contact_tag)";
24+
"Found tags: $(bundle_tags)";
25+
"Contact tag: $(contact_tag)";
1926
}
2027
#+end_src
2128
###############################################################################

examples/hostswithgroup.cf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
body common control
22
{
3-
bundlesequence => { "example" };
4-
inputs => { "$(sys.libdir)/stdlib.cf" };
3+
bundlesequence => { "example" };
4+
inputs => { "$(sys.libdir)/stdlib.cf" };
55
}
66

7-
87
bundle agent example
98
{
109
vars:
11-
1210
am_policy_hub::
13-
"host_list" slist => hostswithgroup( "Linux", "name" );
11+
"host_list"
12+
slist => hostswithgroup("Linux", "name");
1413

1514
files:
1615
am_policy_hub::
1716
"/tmp/master_config.cfg"
18-
edit_line => insert_lines("host=$(host_list)"),
19-
create => "true";
17+
edit_line => insert_lines("host=$(host_list)"),
18+
create => "true";
2019
}

examples/is_type.cf

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
#+begin_src cfengine3
22
body common control
33
{
4-
bundlesequence => { "example" };
4+
bundlesequence => { "example" };
55
}
66

77
bundle agent example
88
{
99
vars:
10-
"foo"
11-
data => '{ "bar": true }';
12-
"a" string => "hello";
13-
classes:
14-
"isdata"
15-
expression => is_type("foo", "data");
16-
"isdata_boolean"
17-
expression => is_type("foo[bar]", "data boolean");
18-
"isstring"
19-
expression => is_type("a", "string");
20-
"isint"
21-
expression => is_type("a", "int");
10+
"foo"
11+
data => '{ "bar": true }';
12+
"a"
13+
string => "hello";
2214

15+
classes:
16+
"isdata"
17+
expression => is_type("foo", "data");
18+
"isdata_boolean"
19+
expression => is_type("foo[bar]", "data boolean");
20+
"isstring"
21+
expression => is_type("a", "string");
22+
"isint"
23+
expression => is_type("a", "int");
2324

2425
reports:
25-
isdata::
26+
isdata::
2627
"'foo' is of type 'data'";
27-
isdata_boolean::
28+
isdata_boolean::
2829
"'foo[bar]' is of type 'data boolean'";
29-
isstring::
30+
isstring::
3031
"'a' is of type 'string'";
31-
isint::
32+
isint::
3233
"'a' is of type 'int'";
3334
}
3435

examples/isconnectable.cf

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
1-
# Copyright 2025 Northern.tech AS
2-
3-
# This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
4-
5-
# This program is free software; you can redistribute it and/or modify it
6-
# under the terms of the GNU General Public License as published by the
7-
# Free Software Foundation; version 3.
8-
9-
# This program is distributed in the hope that it will be useful,
10-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
# GNU General Public License for more details.
13-
14-
# You should have received a copy of the GNU General Public License
15-
# along with this program; if not, write to the Free Software
16-
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
17-
18-
# To the extent this program is licensed as part of the Enterprise
19-
# versions of Cfengine, the applicable Commercial Open Source License
20-
# (COSL) may apply to this file if you as a licensee so wish it. See
21-
# included file COSL.txt.
22-
23-
#+begin_src cfengine3
241
body common control
252
{
263
bundlesequence => { "example" };
274
}
5+
286
bundle agent example
297
{
308
classes:
31-
"isconnectable" expression => isconnectable("localhost", 22, "30");
9+
"isconnectable"
10+
expression => isconnectable("localhost", 22, "30");
3211

3312
reports:
3413
isconnectable::
3514
"Port is connectable";
3615
!isconnectable::
3716
"Port is not connectable";
3817
}
39-
#+end_src

examples/useringroup.cf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
#+begin_src cfengine3
22
body common control
33
{
4-
bundlesequence => { "example" };
4+
bundlesequence => { "example" };
55
}
6+
67
bundle agent example
78
{
8-
classes:
9-
"root_in_root" expression => useringroup("root", "root");
9+
classes:
10+
"root_in_root"
11+
expression => useringroup("root", "root");
1012

11-
reports:
12-
root_in_root::
13-
"root is indeed in the root group";
14-
!root_in_root::
15-
"something went wrong";
13+
reports:
14+
root_in_root::
15+
"root is indeed in the root group";
16+
!root_in_root::
17+
"something went wrong";
1618
}
1719
#+end_src
1820
#############################################################################

0 commit comments

Comments
 (0)