]> git.proxmox.com Git - pve-firewall.git/blobdiff - src/PVE/API2/Firewall/Cluster.pm
add macro descriptions (and API to read them)
[pve-firewall.git] / src / PVE / API2 / Firewall / Cluster.pm
index d7146f39970ecee89c5958f73b7bc58255d84978..028600cf4174b62e737df8655c6e9c92115aa9ce 100644 (file)
@@ -50,6 +50,7 @@ __PACKAGE__->register_method({
            { name => 'options' },
            { name => 'groups' },
            { name => 'netgroups' },
+           { name => 'macros' },
            ];
 
        return $result;
@@ -105,6 +106,7 @@ __PACKAGE__->register_method({
     path => 'options',
     method => 'PUT',
     description => "Set Firewall options.",
+    protected => 1,
     parameters => {
        additionalProperties => 0,
        properties => &$add_option_properties({
@@ -133,8 +135,47 @@ __PACKAGE__->register_method({
            $cluster_conf->{options}->{enable} = $param->{enable} ? 1 : 0;
        }
 
-
        PVE::Firewall::save_clusterfw_conf($cluster_conf);
 
        return undef;
     }});
+
+__PACKAGE__->register_method({
+    name => 'get_macros',
+    path => 'macros',
+    method => 'GET',
+    description => "List available macros",
+    parameters => {
+       additionalProperties => 0,
+    },
+    returns => {
+       type => 'array',
+       items => {
+           type => "object",
+           properties => {
+               macro => {
+                   description => "Macro name.",
+                   type => 'string',
+               },
+               descr => {
+                   description => "More verbose description (if available).",
+                   type => 'string',
+               }
+           },
+       },
+    },
+    code => sub {
+       my ($param) = @_;
+
+       my $res = [];
+
+       my ($macros, $descr) = PVE::Firewall::get_macros();
+
+       foreach my $macro (keys %$macros) {
+           push @$res, { macro => $macro, descr => $descr->{$macro} || $macro };
+       }
+
+       return $res;
+    }});
+
+1;