From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 1D9E11FF0B7 for ; Fri, 13 Nov 2026 21:34:28 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 9FE49216D4; Fri, 13 Nov 2026 21:34:05 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v5 05/19] api: plugins/storage/plugin: factor plugin metadata code into helper Date: Fri, 13 Nov 2026 21:33:09 +0100 Message-ID: <20261113203330.932813-6-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113203330.932813-1-m.carrara@proxmox.com> References: <20261113203330.932813-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794602020968 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.295 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: H2A45TOA42OZHACMXP3AAF3A7JMUBPZC X-Message-ID-Hash: H2A45TOA42OZHACMXP3AAF3A7JMUBPZC X-MailFrom: m.carrara@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alfonso Kuen , Thomas Ellmenreich , Jakob Klocker X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Factor the code that builds a plugin's metadata into a helper, in order to reduce the number of places that need to be touched when adding more properties to the returned metadata. Signed-off-by: Max R. Carrara --- src/PVE/API2/Plugins/Storage/Plugin.pm | 35 +++++++++++--------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/PVE/API2/Plugins/Storage/Plugin.pm b/src/PVE/API2/Plugins/Storage/Plugin.pm index 1635a763..82ad9f8e 100644 --- a/src/PVE/API2/Plugins/Storage/Plugin.pm +++ b/src/PVE/API2/Plugins/Storage/Plugin.pm @@ -102,10 +102,20 @@ my sub get_schema_for_plugin : prototype($) ($plugin) { $PLUGIN_SCHEMAS->{$type} = $schema; return $schema; } +my sub build_plugin_metadata($type) { + my $plugin = PVE::Storage::Plugin->lookup($type); + + return { + origin => plugin_origin($plugin), + schema => get_schema_for_plugin($plugin), + type => $type, + }; +} + # plugins/storage/plugin __PACKAGE__->register_method({ name => 'index', path => '', @@ -140,23 +150,17 @@ __PACKAGE__->register_method({ if (defined($origin)) { next if plugin_origin($plugin) ne $origin; } - my $schema = eval { get_schema_for_plugin($plugin) }; + my $metadata = eval { build_plugin_metadata($type) }; if (my $err = $@) { - warn "skipping storage plugin '$type' - cannot build its schema: $err\n"; + warn "skipping storage plugin '$type' - cannot build its metadata - $err"; next; } - my $item = { - origin => $origin, - schema => $schema, - type => $type, - }; - - push($result->@*, $item); + push($result->@*, $metadata); } return $result; }, }); @@ -183,24 +187,15 @@ __PACKAGE__->register_method({ }, returns => $PLUGIN_METADATA_SCHEMA, code => sub($param) { my $param_type = extract_param($param, 'type'); - # Does not fail since `type` is validated first - my $plugin = PVE::Storage::Plugin->lookup($param_type); - - my $schema = eval { get_schema_for_plugin($plugin) }; + my $metadata = eval { build_plugin_metadata($param_type) }; if (my $err = $@) { raise("Cannot build metadata of storage plugin '$param_type' - $err"); } - my $result = { - origin => plugin_origin($plugin), - schema => $schema, - type => $param_type, - }; - - return $result; + return $metadata; }, }); 1; -- 2.47.3