[Twisted-Python] Assigning AMP box senders & receivers from the responder

Glyph glyph at twistedmatrix.com
Tue Jul 3 17:53:28 EDT 2012

On Jul 3, 2012, at 12:08 AM, Laurens Van Houtven <_ at lvh.cc> wrote:

> I'm trying to implement a command called "Become" that allows a staff member to work as if he was the user himself. The most obvious way (to me at least) to do that  to create the customer API (an IBoxReceiver/amp.BoxDispatcher subclass) for that customer (that'd normally be the Realm's job -- but since we're already logged in as an administrator, we don't go through Cred again), and hook up the current connection with that box receiver. Yay, code reuse!

Why not just go through cred again?  (If you look for 'Preauthenticated' in the Divmod code base you'll find that this is actually something of a design pattern.)

> I don't see an obvious way to get a reference to the boxReceiver/boxSender from the responder method using documented APIs. Does this just mean I have to leak a reference to them all the way down? Am I doing something stupid?

This is why the lowest level of argument parsing is fromString*Proto* rather than just fromString.  You can write an Argument that doesn't actually look at the box and gives you any necessary properties from the protocol (or from the transport).  It was originally written so you can ask for the host and peer addresses for P2P stuff, but this is another possible use.

Sorry I don't have time to be more expansive at the moment, I hope that's enough to get you un-stuck,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120703/e6647265/attachment.htm 

More information about the Twisted-Python mailing list