public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	n.frey@proxmox.com
Subject: Re: [pve-devel] [PATCH pve-manager v2 2/4] api: add APT versions return schema
Date: Thu, 2 Oct 2025 10:50:51 +0200	[thread overview]
Message-ID: <cc86f63f-68d6-4824-a3f1-1f401520d677@proxmox.com> (raw)
In-Reply-To: <20250924115904.122696-3-n.frey@proxmox.com>

Am 24.09.25 um 13:59 schrieb n.frey@proxmox.com:
> From: Nicolas Frey <n.frey@proxmox.com>
> 
> listed only supported debian architectures [0] in enum for 'Arch'.
> listed all APT package states in enum for 'CurrentState'.

This is a bit specific and the sentence seems like it starts
somewhere in the middle, maybe this can be lead up to with
adding a little bit more context that avoids that one starts to
wonder what a APT version return schema has to do with Debian A+rchs.

> 
> [0] https://wiki.debian.org/SupportedArchitectures
> 
> Signed-off-by: Nicolas Frey <n.frey@proxmox.com>
> ---
>  PVE/API2/APT.pm | 113 ++++++++++++++++++++++++++++--------------------
>  1 file changed, 67 insertions(+), 46 deletions(-)
> 
> diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm
> index 0d07cf38..885b85ae 100644
> --- a/PVE/API2/APT.pm
> +++ b/PVE/API2/APT.pm

> @@ -769,6 +771,25 @@ __PACKAGE__->register_method({
>      },
>  });
>  
> +$apt_package_return_props->{CurrentState} = {
> +    type => 'string',
> +    description => 'Current state of the package installed on the system.',
> +    # Possible CurrentState variants according to AptPkg::Cache
> +    enum => [qw(Installed NotInstalled UnPacked HalfConfigured HalfInstalled ConfigFiles)],
> +};
> +
> +$apt_package_return_props->{RunningKernel} = {
> +    type => 'string',
> +    description => "Kernel release, only for package 'proxmox-ve'.",
> +    optional => 1,
> +};
> +
> +$apt_package_return_props->{ManagerVersion} = {
> +    type => 'string',
> +    description => "Version of the currently running pve-manager API server.",
> +    optional => 1,
> +};
> +

Modifying a hash reference that is already used above is rather dangerous, as just
some code line movement can introduce different behavior and wrong return types.

You rather should create a new (cloned) variable, e.g.:

my $versions_api_return_schema = {
    $apt_package_return_props->%*,
    CurrentState => {
        ...,
    },
    ...,
}

As this is then only used once you can also do that inline below, as
single-use intermediate variables are most often rather useless and just an
extra indirection. While they sometimes the can indeed help bring clarity,
here it would be pretty clear what's happening without that.

>  __PACKAGE__->register_method({
>      name => 'versions',
>      path => 'versions',
> @@ -788,7 +809,7 @@ __PACKAGE__->register_method({
>          type => "array",
>          items => {
>              type => "object",
> -            properties => {},
> +            properties => sort $apt_package_return_props,
>          },
>      },
>      code => sub {



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


  reply	other threads:[~2025-10-02  8:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-24 11:59 [pve-devel] [PATCH pve-manager v2 0/4] api: add return schemas n.frey
2025-09-24 11:59 ` [pve-devel] [PATCH pve-manager v2 1/4] api: add ACME plugin return schema n.frey
2025-09-24 11:59 ` [pve-devel] [PATCH pve-manager v2 2/4] api: add APT versions " n.frey
2025-10-02  8:50   ` Thomas Lamprecht [this message]
2025-10-02  9:25     ` Nicolas Frey
2025-09-24 11:59 ` [pve-devel] [PATCH pve-manager v2 3/4] api: add service state " n.frey
2025-09-24 11:59 ` [pve-devel] [PATCH pve-manager v2 4/4] api: add replication config read " n.frey
2025-10-02  8:51   ` Thomas Lamprecht
2025-10-02 11:18     ` Nicolas Frey
2025-10-02  8:23 ` [pve-devel] partially-applied: [PATCH pve-manager v2 0/4] api: add return schemas Thomas Lamprecht

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=cc86f63f-68d6-4824-a3f1-1f401520d677@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=n.frey@proxmox.com \
    --cc=pve-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