[pmg-devel] [PATCH WIP api 07/11] match groups: parse field into objects
Leo Nunner
l.nunner at proxmox.com
Thu Sep 14 11:52:28 CEST 2023
Parse the MatchGroup value from the database into the 'group' property of
our abstraction objects. We are skipping this step for 'action' objects.
A function was added to update the MatchGroup value for a specific
object-rule relation.
Signed-off-by: Leo Nunner <l.nunner at proxmox.com>
---
src/PMG/API2/ObjectGroupHelpers.pm | 1 +
src/PMG/RuleCache.pm | 6 ++++--
src/PMG/RuleDB.pm | 5 +++--
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/PMG/API2/ObjectGroupHelpers.pm b/src/PMG/API2/ObjectGroupHelpers.pm
index c3e6448..79e0d70 100644
--- a/src/PMG/API2/ObjectGroupHelpers.pm
+++ b/src/PMG/API2/ObjectGroupHelpers.pm
@@ -51,6 +51,7 @@ sub format_object_group {
name => $og->{name},
info => $og->{info},
negate => $og->{negate},
+ group => $og->{group},
};
}
return $res;
diff --git a/src/PMG/RuleCache.pm b/src/PMG/RuleCache.pm
index 04e35da..115bf1a 100644
--- a/src/PMG/RuleCache.pm
+++ b/src/PMG/RuleCache.pm
@@ -56,7 +56,7 @@ sub new {
my ($from, $to, $when, $what, $action);
my $sth1 = $dbh->prepare(
- "SELECT Objectgroup_ID, Grouptype, Negate FROM RuleGroup " .
+ "SELECT Objectgroup_ID, Grouptype, Negate, MatchGroup FROM RuleGroup " .
"where RuleGroup.Rule_ID = '$ruleid' " .
"ORDER BY Grouptype, Objectgroup_ID");
@@ -65,6 +65,7 @@ sub new {
my $gtype = $ref1->{grouptype};
my $groupid = $ref1->{objectgroup_id};
my $negate = $ref1->{negate};
+ my $group = $ref1->{group};
# emtyp groups differ from non-existent groups!
@@ -91,8 +92,9 @@ sub new {
$sha1->add (join (',', $objid, $gtype, $groupid) . "|");
$sha1->add ($obj->{digest}, "|");
- if ($gtype != 4) { # it doesn't make any sense to negate actions
+ if ($gtype != 4) { # it doesn't make any sense to group or negate actions
$obj->{negate} = $negate;
+ $obj->{group} = $group;
}
if ($gtype == 0) { #from
diff --git a/src/PMG/RuleDB.pm b/src/PMG/RuleDB.pm
index b126d0d..f12f9a0 100644
--- a/src/PMG/RuleDB.pm
+++ b/src/PMG/RuleDB.pm
@@ -106,8 +106,8 @@ sub load_groups {
defined($rule->{id}) || die "undefined rule id: ERROR";
my $sth = $self->{dbh}->prepare(
- "SELECT RuleGroup.Grouptype, Objectgroup.ID, " .
- "Objectgroup.Name, Objectgroup.Info, Negate " .
+ "SELECT RuleGroup.Grouptype, RuleGroup.Negate, RuleGroup.MatchGroup, " .
+ "Objectgroup.ID, Objectgroup.Name, Objectgroup.Info " .
"FROM Rulegroup, Objectgroup " .
"WHERE Rulegroup.Rule_ID = ? and " .
"Rulegroup.Objectgroup_ID = Objectgroup.ID " .
@@ -125,6 +125,7 @@ sub load_groups {
if ($ref->{'grouptype'} != 4) { # this doesn't make any sense for actions
$og->{negate} = $ref->{negate};
+ $og->{group} = $ref->{matchgroup};
}
if ($ref->{'grouptype'} == 0) { #from
--
2.39.2
More information about the pmg-devel
mailing list