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

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Aug 24 13:05:15 CEST 2010


Author: dietmar
Date: 2010-08-24 11:05:14 +0000 (Tue, 24 Aug 2010)
New Revision: 5043

Added:
   pve-common/trunk/RPCEnvironment.pm
Modified:
   pve-common/trunk/ChangeLog
   pve-common/trunk/Makefile
   pve-common/trunk/RESTHandler.pm
Log:
	* RESTHandler.pm (handle): remove $conn parameter. We use new
	RPCEnvironment class to pass environment values.


Modified: pve-common/trunk/ChangeLog
===================================================================
--- pve-common/trunk/ChangeLog	2010-08-23 06:02:15 UTC (rev 5042)
+++ pve-common/trunk/ChangeLog	2010-08-24 11:05:14 UTC (rev 5043)
@@ -1,3 +1,8 @@
+2010-08-24  Proxmox Support Team  <support at proxmox.com>
+
+	* RESTHandler.pm (handle): remove $conn parameter. We use new
+	RPCEnvironment class to pass environment values.
+
 2010-08-20  Proxmox Support Team  <support at proxmox.com>
 
 	* RESTHandler.pm (register_method): allow us to use regex in the

Modified: pve-common/trunk/Makefile
===================================================================
--- pve-common/trunk/Makefile	2010-08-23 06:02:15 UTC (rev 5042)
+++ pve-common/trunk/Makefile	2010-08-24 11:05:14 UTC (rev 5043)
@@ -18,6 +18,7 @@
 DEB=${PACKAGE}_${VERSION}-${PKGREL}_${ARCH}.deb
 
 LIB_SOURCES=			\
+	RPCEnvironment.pm	\
 	RESTHandler.pm		\
 	JSONSchema.pm		\
 	SafeSyslog.pm		\

Modified: pve-common/trunk/RESTHandler.pm
===================================================================
--- pve-common/trunk/RESTHandler.pm	2010-08-23 06:02:15 UTC (rev 5042)
+++ pve-common/trunk/RESTHandler.pm	2010-08-24 11:05:14 UTC (rev 5043)
@@ -51,21 +51,6 @@
     push @{$method_registry->{$self}}, $info;
 }
 
-my $call_local_method = sub {
-    my ($self, $info, $param) = @_;
-
-    # fixme: how do we handle this here?
-    # fixme: language ?
-    my $conn = {
-#	abs_uri => $abs_uri,
-#	rel_uri => $rel_uri,
-#	user => $username,
-	params => $param || {},
-    };
-
-    return $self->handle($info, $conn);
-};
-
 sub AUTOLOAD {
     my $this = shift;
 
@@ -81,7 +66,7 @@
     *$AUTOLOAD = sub {
 	my $self = shift;
 
-	return $self->$call_local_method($info, @_);
+	return $self->handle($info, @_);
     };
     goto &$AUTOLOAD;
 
@@ -185,7 +170,7 @@
 }
 
 sub handle {
-    my ($self, $info, $conn) = @_;
+    my ($self, $info, $param) = @_;
 
     my $func = $info->{code};
 
@@ -195,11 +180,11 @@
     }
 
     if (my $schema = $info->{parameters}) {
-	# warn "validate ". Dumper($conn->{params}) . "\n" . Dumper($schema);
-	PVE::JSONSchema::validate($conn->{params}, $schema);
+	# warn "validate ". Dumper($param}) . "\n" . Dumper($schema);
+	PVE::JSONSchema::validate($param, $schema);
     }
 
-    my $result = &$func($conn, $conn->{params}); 
+    my $result = &$func($param); 
 
     # fixme: this is only to be safe
     if (my $schema = $info->{returns}) {
@@ -216,7 +201,7 @@
 
     my $param = PVE::JSONSchema::get_options($info->{parameters}, $args, $uri_param, $pwcallback);
 
-    return $self->$call_local_method($info, $param);
+    return $self->handle($info, $param);
 }
 
 # utility methods

Added: pve-common/trunk/RPCEnvironment.pm
===================================================================
--- pve-common/trunk/RPCEnvironment.pm	                        (rev 0)
+++ pve-common/trunk/RPCEnvironment.pm	2010-08-24 11:05:14 UTC (rev 5043)
@@ -0,0 +1,43 @@
+package PVE::RPCEnvironment;
+
+use strict;
+use warnings;
+
+# we use this global to pass RPC related environment value
+our $pve_env;
+
+sub init {
+    my ($class) = @_;
+
+    $class = ref($class) || $class;
+
+    die "already initialized" if $pve_env;
+
+    my $self = {
+
+    };
+
+    bless $self, $class;
+
+    $pve_env = $self;
+
+    return $self;
+}; 
+
+sub set_language {
+    my ($self, $lang) = @_;
+
+    # fixme: initialize I18N
+
+    $self->{language} = $lang;
+}
+
+sub set_user {
+    my ($self, $user) = @_;
+
+    # fixme: get ACLs
+
+    $self->{user} = $user;
+}
+
+1;




More information about the pve-devel mailing list