[pve-devel] [PATCH v2 2/3] make path and perm optional parameters

Dominik Csapak d.csapak at proxmox.com
Mon Dec 11 11:28:25 CET 2017


and only pass perm to the api call if it is not empty

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PVE/CLI/termproxy.pm | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/PVE/CLI/termproxy.pm b/src/PVE/CLI/termproxy.pm
index 382270d..7378821 100644
--- a/src/PVE/CLI/termproxy.pm
+++ b/src/PVE/CLI/termproxy.pm
@@ -21,11 +21,15 @@ sub verify_ticket {
 
     my $ua = LWP::UserAgent->new();
 
-    my $res = $ua->post ('http://localhost:85/api2/json/access/ticket', Content => {
-			 username => $user,
-			 password => $ticket,
-			 path => $path,
-			 privs => $perm, });
+    my $params = {
+	username => $user,
+	password => $ticket,
+	path => $path,
+    };
+
+    $params->{privs} = $perm if $perm;
+
+    my $res = $ua->post ('http://localhost:85/api2/json/access/ticket', Content => $params);
 
     if (!$res->is_success) {
 	die "Authentication failed: '$res->status_line'\n";
@@ -209,11 +213,13 @@ __PACKAGE__->register_method ({
 		type => 'string',
 		description => "The Authentication path. (default: '".DEFAULT_PATH."')",
 		default => DEFAULT_PATH,
+		optional => 1,
 	    },
 	    perm => {
 		type => 'string',
 		description => "The Authentication Permission. (default: '".DEFAULT_PERM."')",
 		default => DEFAULT_PERM,
+		optional => 1,
 	    },
 	    'extra-args' => get_standard_option('extra-args'),
 	},
-- 
2.11.0





More information about the pve-devel mailing list