[pve-devel] r5058 - pve-common/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Aug 26 10:12:58 CEST 2010


Author: dietmar
Date: 2010-08-26 08:12:57 +0000 (Thu, 26 Aug 2010)
New Revision: 5058

Modified:
   pve-common/trunk/ChangeLog
   pve-common/trunk/RESTHandler.pm
Log:
	* RESTHandler.pm (usage_str): new '$hidepw' parameter to correctly
	handle hidden password parameter.



Modified: pve-common/trunk/ChangeLog
===================================================================
--- pve-common/trunk/ChangeLog	2010-08-26 06:53:58 UTC (rev 5057)
+++ pve-common/trunk/ChangeLog	2010-08-26 08:12:57 UTC (rev 5058)
@@ -1,5 +1,8 @@
 2010-08-26  Proxmox Support Team  <support at proxmox.com>
 
+	* RESTHandler.pm (usage_str): new '$hidepw' parameter to correctly
+	handle hidden password parameter.
+
 	* README.dev: update docu about find_handler() 
 
 	* RESTHandler.pm (find_handler): use '$path' instead of strange

Modified: pve-common/trunk/RESTHandler.pm
===================================================================
--- pve-common/trunk/RESTHandler.pm	2010-08-26 06:53:58 UTC (rev 5057)
+++ pve-common/trunk/RESTHandler.pm	2010-08-26 08:12:57 UTC (rev 5058)
@@ -209,14 +209,14 @@
 # $arg_param   ... list of parameters we want to get as ordered arguments on the command line
 # $fixed_param ... do not generate and info about those parameters
 # $format:
-#   'long'  ... default (list all options)
-#   'short' ... command line only (one line)
-#   'full'  ... also include description
-#
+#   'long'     ... default (list all options)
+#   'short'    ... command line only (one line)
+#   'full'     ... also include description
+# $hidepw      ... hide password option (use this if you provide a read passwork callback)
+
 sub usage_str {
-    my ($self, $name, $prefix, $arg_param, $fixed_param, $format) = @_;
+    my ($self, $name, $prefix, $arg_param, $fixed_param, $format, $hidepw) = @_;
 
-
     $format = 'long' if !$format;
 
     my $info = $self->map_method_by_name($name);
@@ -241,13 +241,17 @@
     };
 
     my $get_prop_descr = sub {
-	my ($phash, $display_name) = @_;
+	my ($phash, $display_name, $name) = @_;
  
 	my $res = '';
 
 	my $descr = $phash->{description} || "no description available";
 	my $type =  &$get_type_str($phash);
 
+	if ($hidepw && $name eq 'password') {
+	    $type = '';
+	}
+
 	$res .= sprintf "  %-10s %-10s   $descr\n", $display_name, "$type";
 	my $indend = "                          ";
 	if ($phash->{enum}) {
@@ -270,7 +274,7 @@
     foreach my $k (@$arg_param) {
 	next if defined($fixed_param->{$k}); # just to be sure
 
-	$argdescr .= &$get_prop_descr($prop->{$k}, "<$k>");
+	$argdescr .= &$get_prop_descr($prop->{$k}, "<$k>", $k);
     }
 
     my $opts = '';
@@ -280,8 +284,10 @@
 
 	my $type =  &$get_type_str($prop->{$k});
 
-	$opts .= &$get_prop_descr($prop->{$k}, "-$k");
+	next if $hidepw && ($k eq 'password') && !$prop->{$k}->{optional};
 
+	$opts .= &$get_prop_descr($prop->{$k}, "-$k", $k);
+
 	if (!$prop->{$k}->{optional}) {
 	    $args .= " " if $args;
 	    $args .= "-$k $type"
@@ -316,19 +322,16 @@
 	$param->{$p} = $fixed_param->{$p};
     }
 
-    # after copy, we set $fixed_param->{password} to exclude password from usage info.
-    $fixed_param->{password} = 1 if $pwcallback;
-
     foreach my $p (@$arg_param) {
 	my $v = shift @$args;
 
 	if (!defined($v)) {
-	    my $usage = $self->usage_str($name, $prefix, $arg_param, $fixed_param);
+	    my $usage = $self->usage_str($name, $prefix, $arg_param, $fixed_param, undef, $pwcallback);
 	    raise_param_exc({ $p => "got undefined value for required argument"}, $usage); 
 	}
 
 	if ($v =~ m/^-/) {
-	    my $usage = $self->usage_str($name, $prefix, $arg_param, $fixed_param);
+	    my $usage = $self->usage_str($name, $prefix, $arg_param, $fixed_param, undef, $pwcallback);
 	    raise_param_exc({ $p => "required argument may not start with hyphen"}, $usage); 
 	}
 
@@ -346,7 +349,7 @@
 
 	die $err if !$ec || $ec ne "PVE::Exception" || !$err->is_param_exc();
 	
-	$err->{usage} = $self->usage_str($name, $prefix, $arg_param, $fixed_param);
+	$err->{usage} = $self->usage_str($name, $prefix, $arg_param, $fixed_param, undef, $pwcallback);
 
 	die $err;
     }




More information about the pve-devel mailing list