* [pmg-devel] [PATCH pmg-api] pmgdb: dump: replace active flag with rules enum
@ 2024-02-27 14:22 Stoiko Ivanov
2024-02-27 16:01 ` [pmg-devel] applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Stoiko Ivanov @ 2024-02-27 14:22 UTC (permalink / raw)
To: pmg-devel
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>
---
tested by running all 4 variants (active, inactive, all, no rule argument)
and diffing the resulting output)
src/PMG/CLI/pmgdb.pm | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/PMG/CLI/pmgdb.pm b/src/PMG/CLI/pmgdb.pm
index 0ac3f82..cc9d000 100644
--- a/src/PMG/CLI/pmgdb.pm
+++ b/src/PMG/CLI/pmgdb.pm
@@ -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();
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pmg-devel] applied: [PATCH pmg-api] pmgdb: dump: replace active flag with rules enum
2024-02-27 14:22 [pmg-devel] [PATCH pmg-api] pmgdb: dump: replace active flag with rules enum Stoiko Ivanov
@ 2024-02-27 16:01 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2024-02-27 16:01 UTC (permalink / raw)
To: Stoiko Ivanov, pmg-devel
Am 27/02/2024 um 15:22 schrieb Stoiko Ivanov:
> 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>
> ---
> tested by running all 4 variants (active, inactive, all, no rule argument)
> and diffing the resulting output)
> src/PMG/CLI/pmgdb.pm | 18 +++++++++++-------
> 1 file changed, 11 insertions(+), 7 deletions(-)
>
>
While I shortly thought if another option name would be better (e.g.,
rule-selection?), this is mostly for debugging purpose, so I think it
won't matter much anyway.
applied, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-27 16:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 14:22 [pmg-devel] [PATCH pmg-api] pmgdb: dump: replace active flag with rules enum Stoiko Ivanov
2024-02-27 16:01 ` [pmg-devel] applied: " Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox