Fix setting the default token generator via Djblets.

Review Request #12582 — Created Sept. 6, 2022 and submitted

Information

Djblets
release-3.x

Reviewers

The default token generator can be set via
settings.DJBLETS_DEFAULT_API_TOKEN_GENERATOR but this currently takes a class,
which isn't safe to import via settings.py. With this change we instead accept
a token generator ID, which is safe and ensures that we're only using token
generators that are registered.

  • Created new unit tests for getting the default token generator.
  • Ran unit tests in djblets.secrets.tests.
  • Ran unit tests in reviewboard.webapi.tests.
Summary ID
Fix setting the default token generator via Djblets.
9373ea79339567b65decee1fa39d63a4ef8a7c33
Description From Last Updated

Instead of instantiating a second copy of this, how about just returning self.get_token_generator('vendor_checksum')? We could also just assign that to …

daviddavid

Let's change this slightly, to deal with any issue of the generator ID being falsy (if, say, we wanted to …

chipx86chipx86
david
  1. 
      
  2. Show all issues

    Instead of instantiating a second copy of this, how about just returning self.get_token_generator('vendor_checksum')?

    We could also just assign that to token_generator so that this function has a single return statement at the end.

  3. 
      
maubin
chipx86
  1. 
      
  2. djblets/secrets/token_generators/registry.py (Diff revision 2)
     
     
     
     
     
    Show all issues

    Let's change this slightly, to deal with any issue of the generator ID being falsy (if, say, we wanted to provide a default with None somewhere):

    token_generator_id = (
        getattr(settings, '...', None) or
        VendorChecksumTokenGenerator.token_generator_id
    )
    
  3. 
      
maubin
david
  1. Ship It!
  2. 
      
maubin
Review request changed
Status:
Completed
Change Summary:
Pushed to release-3.x (3985e31)