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
12 changes: 12 additions & 0 deletions libenv/sysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3944,7 +3944,19 @@ static void SysPolicyReleaseId(EvalContext *ctx, Policy *policy)
free(release_id);
}

static void SysPolicyVersion(EvalContext *ctx)
{
const char *version = EvalContextVariableControlCommonGet(ctx, COMMON_CONTROL_VERSION);
if (version != NULL)
{
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS, "policy_version", version, CF_DATA_TYPE_STRING,
"inventory,source=agent,attribute_name=CFEngine policy version,derived-from=default:control_common.version");
}
}


void DetectEnvironmentFromPolicy(EvalContext *ctx, Policy *policy)
{
SysPolicyReleaseId(ctx, policy);
SysPolicyVersion(ctx);
}
20 changes: 20 additions & 0 deletions tests/acceptance/01_vars/01_basic/sys_policy_version.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
body common control
{
bundlesequence => { "check" };
version => "1.2.3";
}

bundle agent check
{
classes:
"ok"
expression => and(
strcmp("$(sys.policy_version)", "$(default:control_common.version)"),
strcmp("$(sys.policy_version)", "1.2.3")
);
reports:
ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";
}
16 changes: 16 additions & 0 deletions tests/acceptance/01_vars/01_basic/sys_policy_version_empty.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
body common control
{
bundlesequence => { "check" };
}

bundle agent check
{
classes:
"ok"
expression => not(isvariable("sys.policy_version"));
reports:
ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";
}
Loading