[pmg-devel] [PATCH WIP api 09/11] match groups: list match groups in rule API
Leo Nunner
l.nunner at proxmox.com
Thu Sep 14 11:52:30 CEST 2023
Add a list of all match groups that are associated with a rule when
requesting the rule information via the API.
Signed-off-by: Leo Nunner <l.nunner at proxmox.com>
---
src/PMG/API2/ObjectGroupHelpers.pm | 4 +++-
src/PMG/API2/RuleDB.pm | 4 +++-
src/PMG/API2/Rules.pm | 4 +++-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/PMG/API2/ObjectGroupHelpers.pm b/src/PMG/API2/ObjectGroupHelpers.pm
index 79e0d70..5e15d37 100644
--- a/src/PMG/API2/ObjectGroupHelpers.pm
+++ b/src/PMG/API2/ObjectGroupHelpers.pm
@@ -14,7 +14,7 @@ use PMG::DBTools;
use PMG::RuleDB;
sub format_rule {
- my ($rule, $from, $to, $when, $what, $action) = @_;
+ my ($rule, $from, $to, $when, $what, $action, $match) = @_;
my $cond_create_group = sub {
my ($res, $name, $groupdata) = @_;
@@ -38,6 +38,8 @@ sub format_rule {
$cond_create_group->($data, 'what', $what);
$cond_create_group->($data, 'action', $action);
+ $data->{match} = $match if $match;
+
return $data;
}
diff --git a/src/PMG/API2/RuleDB.pm b/src/PMG/API2/RuleDB.pm
index 1fddb32..3942f36 100644
--- a/src/PMG/API2/RuleDB.pm
+++ b/src/PMG/API2/RuleDB.pm
@@ -141,8 +141,10 @@ __PACKAGE__->register_method({
my ($from, $to, $when, $what, $action) =
$rdb->load_groups($rule);
+ my $matchgroups = $rdb->load_match_groups($rule);
+
my $data = PMG::API2::ObjectGroupHelpers::format_rule(
- $rule, $from, $to, $when, $what, $action);
+ $rule, $from, $to, $when, $what, $action, $matchgroups);
push @$res, $data;
}
diff --git a/src/PMG/API2/Rules.pm b/src/PMG/API2/Rules.pm
index a048872..91e91ed 100644
--- a/src/PMG/API2/Rules.pm
+++ b/src/PMG/API2/Rules.pm
@@ -130,8 +130,10 @@ __PACKAGE__->register_method ({
my ($from, $to, $when, $what, $action) =
$rdb->load_groups($rule);
+ my $matchgroups = $rdb->load_match_groups($rule);
+
my $data = PMG::API2::ObjectGroupHelpers::format_rule(
- $rule, $from, $to, $when, $what, $action);
+ $rule, $from, $to, $when, $what, $action, $matchgroups);
return $data;
}});
--
2.39.2
More information about the pmg-devel
mailing list