]> git.proxmox.com Git - pve-firewall.git/blobdiff - src/PVE/API2/Firewall/Groups.pm
remove useless unused Data::Dumper uses
[pve-firewall.git] / src / PVE / API2 / Firewall / Groups.pm
index 6d9117b00b9eb009face835c7d898e2f16baea6b..8f94b6df72f58bc41bffb9da4e2ea9068cee22fb 100644 (file)
@@ -8,7 +8,6 @@ use PVE::Exception qw(raise raise_param_exc);
 use PVE::Firewall;
 use PVE::API2::Firewall::Rules;
 
-use Data::Dumper; # fixme: remove
 
 use base qw(PVE::RESTHandler);
 
@@ -16,7 +15,7 @@ my $get_security_group_list = sub {
     my ($cluster_conf) = @_;
 
     my $res = [];
-    foreach my $group (keys %{$cluster_conf->{groups}}) {
+    foreach my $group (sort keys %{$cluster_conf->{groups}}) {
        my $data = { 
            group => $group,
        };
@@ -36,6 +35,7 @@ __PACKAGE__->register_method({
     path => '',
     method => 'GET',
     description => "List security groups.",
+    permissions => { user => 'all' },
     parameters => {
        additionalProperties => 0,
        properties => {},
@@ -69,6 +69,9 @@ __PACKAGE__->register_method({
     method => 'POST',
     description => "Create new security group.",
     protected => 1,
+    permissions => {
+       check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
     parameters => {
        additionalProperties => 0,
        properties => { 
@@ -97,6 +100,11 @@ __PACKAGE__->register_method({
            raise_param_exc({ group => "Security group '$param->{rename}' does not exists" }) 
                if !$cluster_conf->{groups}->{$param->{rename}};
 
+           # prevent overwriting an existing group
+           raise_param_exc({ group => "Security group '$param->{group}' does already exist" })
+               if $cluster_conf->{groups}->{$param->{group}} &&
+               $param->{group} ne $param->{rename};
+
            my $data = delete $cluster_conf->{groups}->{$param->{rename}};
            $cluster_conf->{groups}->{$param->{group}} = $data;
            if (my $comment = delete $cluster_conf->{group_comments}->{$param->{rename}}) {