[pve-devel] [PATCH v3] remove read_password from CLIHandler
Thomas Lamprecht
t.lamprecht at proxmox.com
Tue Jun 19 13:12:19 CEST 2018
On 6/15/18 3:28 PM, Dominik Csapak wrote:
> and replace it with param_mapping, since that implements a very
> similar, but more general behaviour
>
> also introduce a get_confirmed_password, as suggested by Thomas[1]
>
> [1]: https://pve.proxmox.com/pipermail/pve-devel/2018-June/032338.html
>
> this further implements a 'get_standard_mapping' sub to
> reuse parameter mappings we often use (like for the password)
>
> pve-common:
>
> Dominik Csapak (4):
> remove read_password_func from cli handler
> add the possibility to use a hash for parameter mapping
> CLIHandler: add standard_mappings
> CLIHandler: add standard mapping for password parameter
>
> src/PVE/CLIHandler.pm | 48 ++++++++++++++++++++++++++++++++++++++----------
> src/PVE/JSONSchema.pm | 15 +--------------
> src/PVE/RESTHandler.pm | 36 +++++++++++++++++++-----------------
> 3 files changed, 58 insertions(+), 41 deletions(-)
>
applied 2/4, 3/4 and 4/4 from the common patches, 1/4 is:
a) nicer to be applied after the helpers
b) some backward compatibility would be nice, as doing both, a breaks here,
plus depends on pve-common in using packages at the same time is a bit of
a PITA and limits users in what combination the could run (e.g., if a
regression gets introduced they need to reverse the whole upgrade not
only the really affected package.
maybe something in the like of (totally untested):
diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
index 20df299..b8c67c0 100644
--- a/src/PVE/CLIHandler.pm
+++ b/src/PVE/CLIHandler.pm
@@ -677,6 +677,22 @@ sub run_cli_handler {
my $param_cb = $cli_handler_class->can('param_mapping') ||
$class->can('string_param_file_mapping');
+ if (my $pw_cb = $class->can('read_password') && !$class->can('param_mapping')) {
+ my $old_param_cb = $param_cb;
+ $param_cb = sub {
+ my ($name) = @_;
+
+ my $mapping = $old_param_cb ? $old_param_cb->{$name} : [];
+ push @$mapping, [
+ get_standard_mapping('pve-password', {
+ func => $pw_cb,
+ })
+ ];
+
+ return $mapping;
+ };
+ }
+
$exename = &$get_exe_name($class);
initlog($exename);
would handle compatibility for handlers with read_password function and
string_param_file_mapping.
(oh, I'll rename $param_mapping_func to $param_cb and $param_mapping_hash
to $param_map, hash is a map already an the callback gets called-back for
each param if there, so $param_cb)
More information about the pve-devel
mailing list