public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Leo Nunner <l.nunner@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH WIP api 03/11] negation: expand/implement API endpoints
Date: Thu, 14 Sep 2023 11:52:24 +0200	[thread overview]
Message-ID: <20230914095234.115469-4-l.nunner@proxmox.com> (raw)
In-Reply-To: <20230914095234.115469-1-l.nunner@proxmox.com>

The existing 'add' enpoint was expanded with a 'negate' parameter, so
that new objects can be added in an already negated state. New API
endpoints were added to get and update the specific group-rule relation
settings (which is only 'negate' for now). These endpoints get added to
all ogroups except 'actions', since negating actions doesn't make much
sense.

Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
---
 src/PMG/API2/Rules.pm | 96 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/src/PMG/API2/Rules.pm b/src/PMG/API2/Rules.pm
index 4f8c10b..ad3f6c7 100644
--- a/src/PMG/API2/Rules.pm
+++ b/src/PMG/API2/Rules.pm
@@ -261,6 +261,11 @@ my $register_rule_group_api = sub {
 		    description => "Groups ID.",
 		    type => 'integer',
 		},
+		negate => {
+		    description => "Negate group.",
+		    type => 'boolean',
+		    optional => 1,
+		},
 	    },
 	},
 	returns => { type => 'null' },
@@ -273,6 +278,10 @@ my $register_rule_group_api = sub {
 
 	    $rdb->rule_add_group($param->{id}, $param->{ogroup}, $name);
 
+	    if (defined($param->{negate})) {
+		$rdb->rule_set_group_setting_negate($param->{negate}, $param->{id}, $param->{ogroup}, $name);
+	    }
+
 	    PMG::DBTools::reload_ruledb();
 
 	    return undef;
@@ -314,6 +323,93 @@ my $register_rule_group_api = sub {
 	    return undef;
 	}});
 
+    if($name ne 'action') {
+	__PACKAGE__->register_method ({
+		name => "get_${name}_group_settings",
+		path => "$name/{ogroup}",
+		method => 'GET',
+		description => "Get '$name' group settings for rule.",
+		proxyto => 'master',
+		protected => 1,
+		permissions => { check => [ 'admin' ] },
+		parameters => {
+		    additionalProperties => 0,
+		    properties => {
+			id => {
+			    description => "Rule ID.",
+			    type => 'integer',
+			},
+			ogroup => {
+			    description => "Groups ID.",
+			    type => 'integer',
+			},
+		    },
+		},
+		returns => {
+		    type => 'array',
+		    items => {
+			type => "object",
+			properties => {
+			    negate => {
+				description=>  "Negate group.",
+				type => 'boolean',
+			    },
+			}
+		    }
+		},
+		code => sub {
+		    my ($param) = @_;
+
+		    my $rdb = PMG::RuleDB->new();
+
+		    my $settings = $rdb->rule_get_group_settings($param->{id}, $param->{ogroup}, $name);
+
+		    my $ret = {
+			negate => $settings->{negate},
+		    };
+
+		    return $ret;
+		}});
+
+	__PACKAGE__->register_method ({
+		name => "set_${name}_group_settings",
+		path => "$name/{ogroup}",
+		method => 'PUT',
+		description => "Update '$name' group settings for rule.",
+		proxyto => 'master',
+		protected => 1,
+		permissions => { check => [ 'admin' ] },
+		parameters => {
+		    additionalProperties => 0,
+		    properties => {
+			id => {
+			    description => "Rule ID.",
+			    type => 'integer',
+			},
+			ogroup => {
+			    description => "Groups ID.",
+			    type => 'integer',
+			},
+			negate => {
+			    description => "Negate group.",
+			    type => 'boolean',
+			    optional => 1,
+			},
+		    },
+		},
+		returns => { type => 'null' },
+		code => sub {
+		    my ($param) = @_;
+
+		    my $rdb = PMG::RuleDB->new();
+
+		    if(defined($param->{negate})) {
+			$rdb->rule_set_group_setting_negate($param->{negate}, $param->{id}, $param->{ogroup}, $name);
+		    }
+
+		    return;
+		}});
+    }
 };
 
 $register_rule_group_api->('from');
-- 
2.39.2





  parent reply	other threads:[~2023-09-14  9:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-14  9:52 [pmg-devel] [PATCH WIP api/gui] Extend rule system Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP api 01/11] negation: add field to database Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP api 02/11] negation: parse negation value into objects Leo Nunner
2023-09-14  9:52 ` Leo Nunner [this message]
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP api 04/11] negation: implement matching logic Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP api 05/11] match groups: update database schema Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP api 06/11] match groups: add functions for database access Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP api 07/11] match groups: parse field into objects Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP api 08/11] match groups: add API endpoints for create/delete Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP api 09/11] match groups: list match groups in rule API Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP api 10/11] match groups: update existing object API endpoints Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP api 11/11] match groups: implement matching logic Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP gui 1/2] negate objects inside rules Leo Nunner
2023-09-14  9:52 ` [pmg-devel] [PATCH WIP gui 2/2] introduce logical 'and' for rules Leo Nunner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230914095234.115469-4-l.nunner@proxmox.com \
    --to=l.nunner@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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