Skip to content

Commit

Permalink
cleanup(load-rules): add support for output and tags in rules append …
Browse files Browse the repository at this point in the history
…mode

Signed-off-by: Melissa Kilby <melissa.kilby.oss@gmail.com>
  • Loading branch information
incertum committed Jul 5, 2023
1 parent 8d68952 commit 5cbff17
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
18 changes: 16 additions & 2 deletions userspace/engine/rule_loader_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ void rule_loader::collector::append(configuration& cfg, rule_info& info)
THROW(!prev,
"Rule has 'append' key but no rule by that name already exists",
info.ctx);
THROW(info.cond.empty() && info.exceptions.empty(),
"Appended rule must have exceptions or condition property",
THROW(info.cond.empty() && info.exceptions.empty() && info.output.empty() && info.tags.empty(),
"Appended rule must have exceptions or condition or output or tags property",
info.ctx);

auto source = cfg.sources.at(prev->source);
Expand All @@ -248,6 +248,20 @@ void rule_loader::collector::append(configuration& cfg, rule_info& info)
prev->cond += info.cond;
}

if (!info.output.empty())
{
prev->output += " ";
prev->output += info.output;
}

if (!info.tags.empty())
{
for (auto itr : info.tags)
{
prev->tags.insert(itr);
}
}

for (auto &ex : info.exceptions)
{
auto prev_ex = find_if(prev->exceptions.begin(), prev->exceptions.end(),
Expand Down
15 changes: 15 additions & 0 deletions userspace/engine/rule_loader_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,27 @@ static void read_item(

if(append)
{
// option to append to condition property
decode_optional_val(item, "condition", v.cond, ctx);
if(item["condition"].IsDefined())
{
v.cond_ctx = rule_loader::context(item["condition"], rule_loader::context::RULE_CONDITION, "", ctx);
}
read_rule_exceptions(item, v, ctx, append);

// option to append to output property
decode_optional_val(item, "output", v.output, ctx);
if(item["output"].IsDefined())
{
v.output_ctx = rule_loader::context(item["output"], rule_loader::context::RULE_OUTPUT, "", ctx);
}
v.output = trim(v.output);
read_rule_exceptions(item, v, ctx, append);

// option to append to tags property
decode_tags(item, v.tags, ctx);
read_rule_exceptions(item, v, ctx, append);

collector.append(cfg, v);
}
else
Expand Down

0 comments on commit 5cbff17

Please sign in to comment.