globus/globus-sdk-python

Feature: Add LazyIdentityMap, based on globus-cli's LazyIdentityMap

sirosen opened this issue · 0 comments

I've found cases outside of the globus-cli where this pattern would be useful.
I also believe it would be healthy to rebuild this tool with some better testing (and less time pressure). I don't intend to work on this starting today, but I'm putting it in the tracker (a) as a wish-list item and (b) in case someone wants to take a crack at contributing it.

LazyIdentityMap is defined here and is specifically meant to speed up rendering of results to the text formatted output. It's batching lookups in groups of 100, and doesn't order the lookups or anything. It's little more than a mild abstraction over a dict.

Here's what I would do if we decided to make it an SDK-level tool:

  1. Change the parameters a bit:
  • Accept IDs or Usernames as inputs
  • Take the AuthClient object as an input
  • Allow tuning of the batch size
  1. Map to the full identity object in the response body, not just one field within it
  2. When a value is looked up, only make one request to populate that part of the map (don't eagerly look up everything)
  3. Allow more IDs to be added to an existing map (mostly because this is easy and I see no reason not to allow it)
  4. Support lookups with __getitem__, possibly implement the full Mapping protocol by supporting __iter__ and __len__
  5. Test, test, test. Because the SDK testsuite is based on fully mocking the socket layer, we can test things in interesting ways. But an additional important test is to modify the globus-cli to use the SDK implementation and ensure that it works (e.g. run its testsuite, run some acl listing commands and other relevant exercises).