public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-firewall] api: rules: add return type to list_rules endpoint
@ 2025-10-22 11:17 Hannes Laimer
  2025-10-22 14:38 ` [pve-devel] applied: " Wolfgang Bumiller
  0 siblings, 1 reply; 2+ messages in thread
From: Hannes Laimer @ 2025-10-22 11:17 UTC (permalink / raw)
  To: pve-devel

We already have this for the GET endpoint for a rule, so we just reuse
that for the items in the list.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
This is a little odd since we return the exact same data in the list as
we do in the endpoint for a single rule. So unless you already know the
pos of a rule, you could just list them and wouldn't need to call
rules/{pos} at all...

We also need this to correctly generate the rust types for the `rules`
endpoint.

 src/PVE/API2/Firewall/Rules.pm | 130 ++++++++++++++++-----------------
 1 file changed, 64 insertions(+), 66 deletions(-)

diff --git a/src/PVE/API2/Firewall/Rules.pm b/src/PVE/API2/Firewall/Rules.pm
index 992ad9a..baed539 100644
--- a/src/PVE/API2/Firewall/Rules.pm
+++ b/src/PVE/API2/Firewall/Rules.pm
@@ -19,6 +19,68 @@ my $api_properties = {
     },
 };
 
+my $rule_return_properties = {
+    action => {
+        type => 'string',
+    },
+    comment => {
+        type => 'string',
+        optional => 1,
+    },
+    dest => {
+        type => 'string',
+        optional => 1,
+    },
+    dport => {
+        type => 'string',
+        optional => 1,
+    },
+    enable => {
+        type => 'integer',
+        optional => 1,
+    },
+    log => PVE::Firewall::get_standard_option(
+        'pve-fw-loglevel',
+        {
+            description => 'Log level for firewall rule',
+        },
+    ),
+    'icmp-type' => {
+        type => 'string',
+        optional => 1,
+    },
+    iface => {
+        type => 'string',
+        optional => 1,
+    },
+    ipversion => {
+        type => 'integer',
+        optional => 1,
+    },
+    macro => {
+        type => 'string',
+        optional => 1,
+    },
+    pos => {
+        type => 'integer',
+    },
+    proto => {
+        type => 'string',
+        optional => 1,
+    },
+    source => {
+        type => 'string',
+        optional => 1,
+    },
+    sport => {
+        type => 'string',
+        optional => 1,
+    },
+    type => {
+        type => 'string',
+    },
+};
+
 =head3 check_privileges_for_method($class, $method_name, $param)
 
 If the permission checks from the register_method() call are not sufficient,
@@ -102,11 +164,7 @@ sub register_get_rules {
             type => 'array',
             items => {
                 type => "object",
-                properties => {
-                    pos => {
-                        type => 'integer',
-                    },
-                },
+                properties => $rule_return_properties,
             },
             links => [{ rel => 'child', href => "{pos}" }],
         },
@@ -151,67 +209,7 @@ sub register_get_rule {
         proxyto => $rule_env eq 'host' ? 'node' : undef,
         returns => {
             type => "object",
-            properties => {
-                action => {
-                    type => 'string',
-                },
-                comment => {
-                    type => 'string',
-                    optional => 1,
-                },
-                dest => {
-                    type => 'string',
-                    optional => 1,
-                },
-                dport => {
-                    type => 'string',
-                    optional => 1,
-                },
-                enable => {
-                    type => 'integer',
-                    optional => 1,
-                },
-                log => PVE::Firewall::get_standard_option(
-                    'pve-fw-loglevel',
-                    {
-                        description => 'Log level for firewall rule',
-                    },
-                ),
-                'icmp-type' => {
-                    type => 'string',
-                    optional => 1,
-                },
-                iface => {
-                    type => 'string',
-                    optional => 1,
-                },
-                ipversion => {
-                    type => 'integer',
-                    optional => 1,
-                },
-                macro => {
-                    type => 'string',
-                    optional => 1,
-                },
-                pos => {
-                    type => 'integer',
-                },
-                proto => {
-                    type => 'string',
-                    optional => 1,
-                },
-                source => {
-                    type => 'string',
-                    optional => 1,
-                },
-                sport => {
-                    type => 'string',
-                    optional => 1,
-                },
-                type => {
-                    type => 'string',
-                },
-            },
+            properties => $rule_return_properties,
         },
         code => sub {
             my ($param) = @_;
-- 
2.47.3



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-22 14:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-22 11:17 [pve-devel] [PATCH pve-firewall] api: rules: add return type to list_rules endpoint Hannes Laimer
2025-10-22 14:38 ` [pve-devel] applied: " Wolfgang Bumiller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal