]> git.proxmox.com Git - pmg-api.git/commitdiff
pmgdb: dump: replace active flag with rules enum
authorStoiko Ivanov <s.ivanov@proxmox.com>
Tue, 27 Feb 2024 14:22:03 +0000 (15:22 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 27 Feb 2024 15:54:41 +0000 (16:54 +0100)
this addresses the odd/unintuitive behavior of `pmgdb dump --active 0`
which currently prints all rules, why printing only the inactive ones
might be expected.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PMG/CLI/pmgdb.pm

index 0ac3f824ecb749e9c31e15b085e98e4e035a277b..cc9d000488f0c1ad60ae70d31b008b033381e156 100644 (file)
@@ -39,11 +39,13 @@ sub print_objects {
 }
 
 sub print_rule {
-    my ($ruledb, $rule, $active_only) = @_;
+    my ($ruledb, $rule, $rule_status) = @_;
 
     $ruledb->load_rule_attributes($rule);
 
-    return if !$rule->{active} && $active_only;
+    return if !$rule->{active} && $rule_status eq 'active';
+    return if $rule->{active} && $rule_status eq 'inactive';
+
     my $direction = {
        0 => 'in',
        1 => 'out',
@@ -114,11 +116,12 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           active => {
-               type => 'boolean',
-               description => "Print only active rules",
+           rules => {
+               description => "Which rules should be printed",
+               type => 'string',
+               enum => [qw(all active inactive)],
+               default => 'all',
                optional => 1,
-               default => 0,
            },
        },
     },
@@ -126,13 +129,14 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
+       my $rule_status = $param->{rules} // '';
        my $dbh = PMG::DBTools::open_ruledb("Proxmox_ruledb");
        my $ruledb = PMG::RuleDB->new($dbh);
 
        my $rules = $ruledb->load_rules();
 
        foreach my $rule (@$rules) {
-           print_rule($ruledb, $rule, $param->{active});
+           print_rule($ruledb, $rule, $rule_status);
        }
 
        $ruledb->close();