By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

SimpleRPCServer

P: n/a
I am trying to restrict some of the methods available by RPC to whether
the user is connected through a ssh-tunnel eg. connecting from localhost.

class UserRPC:
'''Methods available to users'''
pass

class AdminRPC(UserRPC):
'''Methods available only when connecting from localhost'''
pass

class RPCServer(SimpleXMLRPCServer):
def _dispatch(self, method, args):
if user_is_connecting_from_localhost():
return getattr(AdminRPC(), method)(*args)
return getattr(UserRPC(), method)(*args)

What i don't know is how to the client ip. I would think I should
override the _marshalled_dispatch method but I can't quite grasp it all.

/Esben
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Esben> What i don't know is how to the client ip. I would think I should
Esben> override the _marshalled_dispatch method but I can't quite grasp
Esben> it all.

First, from my reading of SimpleXMLRPCServer, I don't think _dispatch()
belongs at that level. It belongs in the request handler class or in a
separate dispatcher class, depending on what version of Python you're using.
Second, SimpleXMLRPCServer is a SocketServer subclass. You should be able
to provide a verify_request method (see the SocketServer docs) and a handler
class with a set_local method:

class RPCServer(SimpleXMLRPCServer):
def verify_request(self, handler, address):
handler.set_local(address_is_local(address))

A _dispatch method in the handler will then be able to check an attribute to
know if the request was made from the local machine or not.

Skip

Jul 18 '05 #2

P: n/a
Skip Montanaro <sk**@pobox.com> wrote:
First, from my reading of SimpleXMLRPCServer, I don't think _dispatch()
belongs at that level. It belongs in the request handler class or in a
separate dispatcher class, depending on what version of Python you're using.


Quite so. As a variant I just use verify_request() to persist the
client IP address, and then wait until _dispatch() to do everything
else.

class RPCServer(SimpleXMLRPCServer):
def verify_request(self, handler, address):
self.client_ip, self.client_port = address
return True

def _dispatch(self, method, args):
do_something(self.client_ip)

Though using a firewall would not be remiss. :-)

-- robin
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.