[pmg-devel] [RFC PATCH pmg-api 07/11] RuleCache: load rule/objectgroup attributes from database

Dominik Csapak d.csapak at proxmox.com
Thu Feb 1 16:36:53 CET 2024


so that we can use the 'and' and 'invert' flags set.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PMG/RuleCache.pm | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/PMG/RuleCache.pm b/src/PMG/RuleCache.pm
index 4f7ebe7..0b62aeb 100644
--- a/src/PMG/RuleCache.pm
+++ b/src/PMG/RuleCache.pm
@@ -67,6 +67,23 @@ sub new {
 	    $self->{"$ruleid:what"} = { groups => [] };
 	    $self->{"$ruleid:action"} = { groups => [] };
 
+	    my $attribute_sth = $dbh->prepare("SELECT * FROM Rule_Attributes WHERE Rule_ID = ?");
+	    $attribute_sth->execute($ruleid);
+
+	    while (my $ref = $attribute_sth->fetchrow_hashref()) {
+		$self->{"$ruleid:from"}->{and} = $ref->{value} if $ref->{name} eq 'from-and';
+		$self->{"$ruleid:from"}->{invert} = $ref->{value} if $ref->{name} eq 'from-invert';
+
+		$self->{"$ruleid:to"}->{and} = $ref->{value} if $ref->{name} eq 'to-and';
+		$self->{"$ruleid:to"}->{invert} = $ref->{value} if $ref->{name} eq 'to-invert';
+
+		$self->{"$ruleid:when"}->{and} = $ref->{value} if $ref->{name} eq 'when-and';
+		$self->{"$ruleid:when"}->{invert} = $ref->{value} if $ref->{name} eq 'when-invert';
+
+		$self->{"$ruleid:what"}->{and} = $ref->{value} if $ref->{name} eq 'what-and';
+		$self->{"$ruleid:what"}->{invert} = $ref->{value} if $ref->{name} eq 'what-invert';
+	    }
+
 	    my $sth1 = $dbh->prepare(
 		"SELECT Objectgroup_ID, Grouptype FROM RuleGroup " .
 		"where RuleGroup.Rule_ID = '$ruleid' " .
@@ -114,6 +131,14 @@ sub new {
 		    objects => $objects,
 		};
 
+		my $objectgroup_sth = $dbh->prepare("SELECT * FROM Objectgroup_Attributes WHERE Objectgroup_ID = ?");
+		$objectgroup_sth->execute($groupid);
+
+		while (my $ref = $objectgroup_sth->fetchrow_hashref()) {
+		    $group->{and} = $ref->{value} if $ref->{name} eq 'and';
+		    $group->{invert} = $ref->{value} if $ref->{name} eq 'invert';
+		}
+
 		my $type = $type_map->{$gtype};
 		push $self->{"$ruleid:$type"}->{groups}->@*, $group;
 	    }
-- 
2.30.2





More information about the pmg-devel mailing list