]> git.proxmox.com Git - pmg-api.git/commitdiff
RuleCache: load rule/objectgroup attributes from database
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 21 Feb 2024 12:24:31 +0000 (13:24 +0100)
committerStoiko Ivanov <s.ivanov@proxmox.com>
Wed, 21 Feb 2024 18:30:13 +0000 (19:30 +0100)
so that we can use the 'and' and 'invert' flags set.

This also adds the attributes to the digest of the rule cache so the
cluster sync is triggered when the attributes change.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PMG/RuleCache.pm

index cd5634254cd9e7116deb68d299d3e2679868864b..4bde2e7cbd5bb088edba69e312fc40caae6dcf69 100644 (file)
@@ -67,6 +67,21 @@ sub new {
            $self->{"$ruleid:what"} = { groups => [] };
            $self->{"$ruleid:action"} = { groups => [] };
 
+           my $attribute_sth = $dbh->prepare("SELECT * FROM Rule_Attributes WHERE Rule_ID = ? ORDER BY Name");
+           $attribute_sth->execute($ruleid);
+
+           my $rule_attributes = [];
+           while (my $ref = $attribute_sth->fetchrow_hashref()) {
+               if ($ref->{name} =~ m/^(from|to|when|what)-(and|invert)$/) {
+                   my $type = $1;
+                   my $prop = $2;
+                   my $value = $ref->{value};
+                   $self->{"${ruleid}:${type}"}->{$prop} = $value;
+
+                   $sha1->add("${ruleid}:${type}-${prop}=${value}|");
+               }
+           }
+
            my $sth1 = $dbh->prepare(
                "SELECT Objectgroup_ID, Grouptype FROM RuleGroup " .
                "where RuleGroup.Rule_ID = '$ruleid' " .
@@ -114,6 +129,15 @@ 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';
+               }
+               $sha1->add (join(',', $groupid, $group->{and} // 0, $group->{invert} // 0), "|");
+
                my $type = $type_map->{$gtype};
                push $self->{"$ruleid:$type"}->{groups}->@*, $group;
            }