From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id D62981FF380
	for <inbox@lore.proxmox.com>; Fri, 19 Apr 2024 14:59:40 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 270069648;
	Fri, 19 Apr 2024 14:59:41 +0200 (CEST)
Message-ID: <5d34cda3-5c8a-48d2-a5c5-9af8d4718b54@proxmox.com>
Date: Fri, 19 Apr 2024 14:59:07 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Lukas Wagner <l.wagner@proxmox.com>
References: <20240415082614.2515677-1-l.wagner@proxmox.com>
 <20240415082614.2515677-9-l.wagner@proxmox.com>
Content-Language: en-US
From: Fiona Ebner <f.ebner@proxmox.com>
In-Reply-To: <20240415082614.2515677-9-l.wagner@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.069 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH manager v5 08/16] api: notification: add API
 for getting known metadata fields/values
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Am 15.04.24 um 10:26 schrieb Lukas Wagner:
> This new API route returns known notification metadata fields and
> a list of known possible values. This will be used by the UI to
> provide suggestions when adding/modifying match rules.
> 
> Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
> ---
>  PVE/API2/Cluster/Notifications.pm | 152 ++++++++++++++++++++++++++++++
>  1 file changed, 152 insertions(+)
> 
> diff --git a/PVE/API2/Cluster/Notifications.pm b/PVE/API2/Cluster/Notifications.pm
> index 68fdda2a..16548bec 100644
> --- a/PVE/API2/Cluster/Notifications.pm
> +++ b/PVE/API2/Cluster/Notifications.pm
> @@ -79,12 +79,164 @@ __PACKAGE__->register_method ({
>  	    { name => 'endpoints' },
>  	    { name => 'matchers' },
>  	    { name => 'targets' },
> +	    { name => 'fields' },

matcher-fields ?

> +	    { name => 'values' },

(matcher-)field-values ?

>  	];
>  
>  	return $result;
>      }
>  });
>  
> +__PACKAGE__->register_method ({
> +    name => 'get_fields',
> +    path => 'fields',
> +    method => 'GET',
> +    description => 'Returns known notification metadata fields and their known values',

It does not return their values.

> +    permissions => {
> +	check => ['or',
> +	    ['perm', '/mapping/notifications', ['Mapping.Modify']],
> +	    ['perm', '/mapping/notifications', ['Mapping.Audit']],
> +	],
> +    },
> +    protected => 1,

No need for protected when all it's doing is returning static info.
(This would have the privileged pvedaemon execute the request).

> +    parameters => {
> +	additionalProperties => 0,
> +	properties => {},
> +    },
> +    returns => {
> +	type => 'array',
> +	items => {
> +	    type => 'object',
> +	    properties => {
> +		name => {
> +		    description => 'Name of the field.',
> +		    type => 'string',
> +		},
> +	    },
> +	},
> +	links => [ { rel => 'child', href => '{name}' } ],
> +    },
> +    code => sub {
> +	# TODO: Adapt this API handler once we have a 'notification registry'
> +
> +	my $result = [
> +	    { name => 'type' },
> +	    { name => 'hostname' },
> +	    { name => 'backup-job' },
> +	    { name => 'replication-job' },
> +	];
> +
> +	return $result;
> +    }
> +});
> +
> +__PACKAGE__->register_method ({
> +    name => 'get_field_values',
> +    path => 'values',
> +    method => 'GET',
> +    description => 'Returns known notification metadata fields and their known values',
> +    permissions => {
> +	check => ['or',
> +	    ['perm', '/mapping/notifications', ['Mapping.Modify']],
> +	    ['perm', '/mapping/notifications', ['Mapping.Audit']],
> +	],
> +    },
> +    protected => 1,
> +    parameters => {
> +	additionalProperties => 0,
> +    },
> +    returns => {
> +	type => 'array',
> +	items => {
> +	    type => 'object',
> +	    properties => {
> +		'value' => {
> +		    description => 'Notification metadata value known by the system.',
> +		    type => 'string'
> +		},
> +		'comment' => {
> +		    description => 'Additional comment for this value.',
> +		    type => 'string',
> +		    optional => 1,
> +		},
> +		'field' => {
> +		    description => 'Field this value belongs to.',
> +		    type => 'string',
> +		    optional => 1,

Why is the field optional? All values are associated to a field below.

> +		},
> +		'internal' => {
> +		    description => 'Set if "value" was generated by the system and can'
> +		       . ' safely be used as base for translations.',
> +		    type => 'boolean',
> +		    optional => 1,
> +		},

Hmm, not sure about this one. It's only used for the type field right?
Can't we just handle that specially in the UI?


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