Skip to content

Commit 4207ed2

Browse files
committed
Added policy examples for formatting
Signed-off-by: Ole Herman Schumacher Elgesem <[email protected]>
1 parent 9598fd2 commit 4207ed2

File tree

6 files changed

+283
-0
lines changed

6 files changed

+283
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bundle agent main { reports: "Hello, world!"; }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bundle agent main
2+
{
3+
reports:
4+
"Hello, world!";
5+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This shows some basics of policy language, without getting
2+
# too deep into edge cases and wrappting etc.
3+
4+
body common control
5+
{
6+
inputs => {"/var/cfengine/inputs/some_file.cf"};
7+
linux::
8+
inputs => {"/var/cfengine/inputs/other_file.cf"};
9+
}
10+
11+
promise agent example
12+
{
13+
interpreter => "/usr/bin/python3";
14+
linux::
15+
path => "/var/cfengine/inputs/modules/promises/git.py";
16+
windows::
17+
path => "C:\Program files\Cfengine\inputs\modules\promises\git.py";
18+
}
19+
20+
bundle agent main
21+
{
22+
vars:
23+
# Comment before promise
24+
"foo"
25+
if => "bar"
26+
string => "some_value";
27+
baz::
28+
"bam"
29+
if => "bar"
30+
# Comment at atttribute level
31+
string => "some_value";
32+
}

tests/format/002_basics.input.cf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This shows some basics of policy language, without getting
2+
# too deep into edge cases and wrappting etc.
3+
4+
body common control{
5+
inputs => { "/var/cfengine/inputs/some_file.cf" };
6+
linux::
7+
inputs => { "/var/cfengine/inputs/other_file.cf" };
8+
}
9+
10+
promise agent example{
11+
interpreter => "/usr/bin/python3";
12+
linux::
13+
path => "/var/cfengine/inputs/modules/promises/git.py";
14+
windows::
15+
path => "C:\Program files\Cfengine\inputs\modules\promises\git.py";
16+
}
17+
18+
bundle agent main {
19+
vars:
20+
# Comment before promise
21+
"foo"
22+
if => "bar"
23+
string => "some_value";
24+
baz::
25+
"bam"
26+
if => "bar"
27+
# Comment at atttribute level
28+
string => "some_value";
29+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
bundle agent strings
2+
{
3+
vars:
4+
# Single-line promises are allowed, as long as there is only 1 attribute,
5+
# and the whole promise fits in less than 80 chars.
6+
"some_variable_name" string => "some_long_variable_value_but_not_past_80";
7+
8+
# Split attribute to separate line if we go over 80:
9+
"some_variable_name"
10+
string => "some_other_variable_value_which_would go_past_80";
11+
12+
# Also split to separate lines if more than one attribute:
13+
"some_variable_name"
14+
if => "any",
15+
string => "some_long_variable_value_but_not_past_80";
16+
17+
"some_variable_name"
18+
string => "sometimes strings are just too long and we cannot do anything about it, leave them as is";
19+
}
20+
21+
bundle agent slists
22+
{
23+
vars:
24+
"variable_name" slist => {"one", "two", "three", "four", "five", "six"};
25+
26+
"variable_name"
27+
slist => {"one", "two", "three", "four", "five", "six", "seven"};
28+
29+
"variable_name"
30+
slist => {
31+
"one", "two", "three", "four", "five", "six", "seven", "eight"
32+
};
33+
34+
"variable_name"
35+
slist => {
36+
"one",
37+
"two",
38+
"three",
39+
"four",
40+
"five",
41+
"six",
42+
"seven",
43+
"eight",
44+
"ten",
45+
"eleven",
46+
};
47+
}
48+
49+
bundle agent function_calls
50+
{
51+
vars:
52+
"variable_name" string => concat("one", "two", "three", "four", "five");
53+
54+
"variable_name"
55+
string => concat("one", "two", "three", "four", "five", "six");
56+
57+
"variable_name"
58+
string => concat(
59+
"one", "two", "three", "four", "five", "six", "seven", "eight"
60+
);
61+
62+
"variable_name"
63+
string => concat(
64+
"one",
65+
"two",
66+
"three",
67+
"four",
68+
"five",
69+
"six",
70+
"seven",
71+
"eight",
72+
"nine",
73+
"ten",
74+
);
75+
}
76+
77+
bundle agent nested_function_calls
78+
{
79+
vars:
80+
"variable_name" string => concat("one", concat("two", "three", "four"));
81+
82+
"variable_name"
83+
string => concat("one", concat("two", "three", "four", "five"));
84+
85+
"variable_name"
86+
string => concat(
87+
"one", concat("two", "three", "four", "five", "six", "seven")
88+
);
89+
90+
"variable_name"
91+
string => concat(
92+
"one",
93+
concat("two", "three", "four", "five", "six", "seven", "eight", ""),
94+
);
95+
96+
"variable_name"
97+
string => concat(
98+
"one",
99+
concat(
100+
"two", "three", "four", "five", "six", "seven", "eight", "nine", ""
101+
),
102+
);
103+
104+
"variable_name"
105+
string => concat(
106+
"one",
107+
concat(
108+
"two",
109+
"three",
110+
"four",
111+
"five",
112+
"six",
113+
"seven",
114+
"eight",
115+
"nine",
116+
"ten",
117+
),
118+
);
119+
}

tests/format/003_wrapping.input.cf

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
bundle agent strings
2+
{
3+
vars:
4+
# Single-line promises are allowed, as long as there is only 1 attribute,
5+
# and the whole promise fits in less than 80 chars.
6+
"some_variable_name"
7+
string => "some_long_variable_value_but_not_past_80";
8+
# Split attribute to separate line if we go over 80:
9+
"some_variable_name"
10+
string => "some_other_variable_value_which_would go_past_80";
11+
# Also split to separate lines if more than one attribute:
12+
"some_variable_name"
13+
if => "any",
14+
string => "some_long_variable_value_but_not_past_80";
15+
"some_variable_name"
16+
string => "sometimes strings are just too long and we cannot do anything about it, leave them as is";
17+
}
18+
19+
bundle agent slists
20+
{
21+
vars:
22+
"variable_name"
23+
slist => { "one", "two", "three", "four", "five", "six" };
24+
"variable_name"
25+
slist => { "one", "two", "three", "four", "five", "six", "seven" };
26+
"variable_name"
27+
slist => {
28+
"one", "two", "three", "four", "five", "six", "seven", "eight"
29+
};
30+
"variable_name"
31+
slist => {
32+
"one",
33+
"two",
34+
"three",
35+
"four",
36+
"five",
37+
"six",
38+
"seven",
39+
"eight",
40+
"ten",
41+
"eleven",
42+
};
43+
}
44+
45+
bundle agent function_calls
46+
{
47+
vars:
48+
"variable_name"
49+
string => concat("one", "two", "three", "four", "five");
50+
"variable_name"
51+
string => concat("one", "two", "three", "four", "five", "six");
52+
"variable_name"
53+
string => concat(
54+
"one", "two", "three", "four", "five", "six", "seven", "eight"
55+
);
56+
"variable_name"
57+
string => concat(
58+
"one",
59+
"two",
60+
"three",
61+
"four",
62+
"five",
63+
"six",
64+
"seven",
65+
"eight",
66+
"nine",
67+
"ten",
68+
);
69+
}
70+
71+
bundle agent nested_function_calls
72+
{
73+
vars:
74+
"variable_name"
75+
string => concat("one", concat("two", "three", "four"));
76+
"variable_name"
77+
string => concat("one", concat("two", "three", "four", "five"));
78+
"variable_name"
79+
string => concat(
80+
"one", concat("two", "three", "four", "five", "six", "seven")
81+
);
82+
"variable_name"
83+
string => concat(
84+
"one",
85+
concat("two", "three", "four", "five", "six", "seven", "eight", ""),
86+
);
87+
"variable_name"
88+
string => concat(
89+
"one",
90+
concat("two", "three", "four", "five", "six", "seven", "eight", "nine", ""),
91+
);
92+
"variable_name"
93+
string => concat(
94+
"one",
95+
concat("two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", ),
96+
);
97+
}

0 commit comments

Comments
 (0)