Skip to content

Commit 46f0b15

Browse files
ENT-13824: Error on rval call that are not builtin-functions inside vars-promise
Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>
1 parent 0e94a6f commit 46f0b15

4 files changed

Lines changed: 76 additions & 0 deletions

File tree

src/cfengine_cli/lint.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,26 @@ def _lint_node(node: Node, policy_file: PolicyFile, state: State) -> int:
515515
f"Error: Call to unknown function / bundle / body '{name}' {location}"
516516
)
517517
return 1
518+
if (
519+
name not in BUILTIN_FUNCTIONS
520+
and state.promise_type == "vars"
521+
and state.attribute_name not in ("action", "classes")
522+
):
523+
_highlight_range(node, lines)
524+
print(
525+
f"Error: Call to unknown function '{name}' inside 'vars'-promise {location}"
526+
)
527+
return 1
528+
if (
529+
state.promise_type == "vars"
530+
and state.attribute_name in ("action", "classes")
531+
and qualified_name not in state.bodies
532+
):
533+
_highlight_range(node, lines)
534+
print(
535+
f"Error: '{name}' is not a defined body. Only bodies may be called with '{state.attribute_name}' {location}"
536+
)
537+
return 1
518538
return 0
519539

520540

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
body classes bundle_class(a)
2+
{
3+
scope => "bundle";
4+
promise_kept => { "$(a):bundle_context" };
5+
}
6+
7+
bundle agent target(a)
8+
{
9+
reports:
10+
"Hello, $(a)";
11+
}
12+
13+
bundle agent helper
14+
{
15+
vars:
16+
"x" string => isvariable("arg");
17+
"y"
18+
classes => bundle_class("arg"),
19+
string => "";
20+
methods:
21+
"x" usebundle => target("arg");
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
vars:
3+
"x" string => target("arg");
4+
^----^
5+
Error: Call to unknown function 'target' inside 'vars'-promise at tests/lint/010_unknown_function_inside_vars.x.cf:16:19
6+
7+
"y"
8+
classes => isvariable("arg"),
9+
^--------^
10+
Error: 'isvariable' is not a defined body. Only bodies may be called with 'classes' at tests/lint/010_unknown_function_inside_vars.x.cf:18:18
11+
FAIL: tests/lint/010_unknown_function_inside_vars.x.cf (2 errors)
12+
Failure, 2 errors in total.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
body classes bundle_class(a)
2+
{
3+
scope => "bundle";
4+
promise_kept => { "$(a):bundle_context" };
5+
}
6+
7+
bundle agent target(a)
8+
{
9+
reports:
10+
"Hello, $(a)";
11+
}
12+
13+
bundle agent helper
14+
{
15+
vars:
16+
"x" string => target("arg");
17+
"y"
18+
classes => isvariable("arg"),
19+
string => "";
20+
methods:
21+
"x" usebundle => target("arg");
22+
}

0 commit comments

Comments
 (0)