Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/macos_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jobs:
run: >
./autogen.sh --enable-debug
- name: Compile and link
run: make -j8 CFLAGS="-Werror -Wall"
run: MACOSX_DEPLOYMENT_TARGET=15.4 make -j8 CFLAGS="-Werror -Wall"
- name: Run unit tests
run: make -C tests/unit check
2 changes: 2 additions & 0 deletions cf-agent/cf-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ int main(int argc, char *argv[])
/* not a fatal issue, let's continue the bootstrap process */
}

GenericAgentDetectEnvironmentFromPolicy(ctx, policy);

int ret = 0;

GenericAgentPostLoadInit(ctx);
Expand Down
23 changes: 23 additions & 0 deletions libenv/sysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3888,3 +3888,26 @@ void DetectEnvironment(EvalContext *ctx)
SysOsVersionMajor(ctx);
SysOsVersionMinor(ctx);
}

static void SysPolicyReleaseId(EvalContext *ctx, Policy *policy)
{
DataType type;
const char *entry_dirname = EvalContextVariableGetSpecial(ctx, SPECIAL_SCOPE_SYS, "policy_entry_dirname", &type);
if (entry_dirname == NULL || policy == NULL)
{
return;
}
char *release_id;
xasprintf(&release_id, "%s/%s", entry_dirname, policy->release_id);

EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS,
"policy_release_id",
release_id,
CF_DATA_TYPE_STRING, "source=agent,attribute_name=Policy Release Id");
free(release_id);
}

void DetectEnvironmentFromPolicy(EvalContext *ctx, Policy *policy)
{
SysPolicyReleaseId(ctx, policy);
}
1 change: 1 addition & 0 deletions libenv/sysinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <eval_context.h>

void DetectEnvironment(EvalContext *ctx);
void DetectEnvironmentFromPolicy(EvalContext *ctx, Policy *policy);

void CreateHardClassesFromCanonification(EvalContext *ctx, const char *canonified, char *tags);
int GetUptimeMinutes(time_t now);
Expand Down
5 changes: 5 additions & 0 deletions libpromises/generic_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -2944,3 +2944,8 @@ void GenericAgentShowVariablesFormatted(EvalContext *ctx, const char *regexp)
SeqDestroy(seq);
VariableTableIteratorDestroy(iter);
}

void GenericAgentDetectEnvironmentFromPolicy(EvalContext *ctx, Policy *policy)
{
DetectEnvironmentFromPolicy(ctx, policy);
}
2 changes: 2 additions & 0 deletions libpromises/generic_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,6 @@ void LoadAugments(EvalContext *ctx, GenericAgentConfig *config);
void GenericAgentShowContextsFormatted(EvalContext *ctx, const char *regexp);
void GenericAgentShowVariablesFormatted(EvalContext *ctx, const char *regexp);

void GenericAgentDetectEnvironmentFromPolicy(EvalContext *ctx, Policy *policy);

#endif
30 changes: 30 additions & 0 deletions tests/acceptance/01_vars/01_basic/policy_release_id.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
body common control
{
bundlesequence => { "test" };
}


bundle agent test
{
vars:
"release_id_list" slist => variablesmatching("default:sys.policy_release_id");
"escaped" string => escape("$(sys.policy_entry_dirname)");
"release_id_regex" string => "^$(escaped)\/([A-Fa-f0-9]+|bootstrap|failsafe|\(null\))+$";

classes:
"var_ok" expression => strcmp("$(release_id_list)", "default:sys.policy_release_id");
"reg_ok" expression => regcmp("$(release_id_regex)", "$(sys.policy_release_id)");
"ok" expression => and("var_ok", "reg_ok");

reports:
DEBUG::
"Found: $(release_id_list), Correct: $(sys.policy_release_id)";
DEBUG.var_ok::
"var ok";
DEBUG.reg_ok::
"reg_ok";
ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";
}
Loading