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 <[email protected]> --- 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 757ae1e..457c070 100644 --- a/src/PVE/API2/Plugins/Storage/Plugin.pm +++ b/src/PVE/API2/Plugins/Storage/Plugin.pm @@ -65,6 +65,19 @@ my sub get_schema_for_plugin : prototype($) ($plugin) { return $schema; } +my sub build_plugin_metadata : prototype($) ($type) { + my $plugin = eval { PVE::Storage::Plugin->lookup($type) }; + if ($@) { + raise("Plugin '$type' not found - $@", code => HTTP_NOT_FOUND); + } + + return { + module => $plugin, + schema => get_schema_for_plugin($plugin), + type => $type, + }; +} + # plugins/storage/plugin __PACKAGE__->register_method({ @@ -87,14 +100,7 @@ __PACKAGE__->register_method({ my $result = []; for my $type ($ALL_PLUGIN_TYPES->@*) { - my $plugin = PVE::Storage::Plugin->lookup($type); - - my $item = { - module => $plugin, - schema => get_schema_for_plugin($plugin), - type => $type, - }; - + my $item = build_plugin_metadata($type); push($result->@*, $item); } @@ -124,18 +130,7 @@ __PACKAGE__->register_method({ code => sub($param) { my $param_type = extract_param($param, 'type'); - my $plugin = eval { PVE::Storage::Plugin->lookup($param_type) }; - if ($@) { - raise("Plugin '$param_type' not found - $@", code => HTTP_NOT_FOUND); - } - - my $result = { - module => $plugin, - schema => get_schema_for_plugin($plugin), - type => $param_type, - }; - - return $result; + return build_plugin_metadata($param_type); }, }); 1; -- 2.47.3 _______________________________________________ pve-devel mailing list [email protected] https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
