Update WebAPITokenManager to use token generators
Review Request #12419 — Created June 28, 2022 and submitted
Currently, token generation is baked into
djblets.webapi.managers.WebAPITokenManager
. With our move to API Tokens v2,
we don't want token generation to be tightly coupled with Web API tokens. We
want tokens to be usable outside of just the API.This change moves token generation out of
WebAPITokenManager
by making use of
token generators instead of directly generating tokens inWebAPITokenManager
.
To do this we add two new parameters toWebAPITokenManager
,
token_generator_id
to decide what token generator to use andtoken_info
to
pass along information needed for token generation to the token generator.
- Updated
WebAPITokenManager
's unit tests to account for the use
of token generators. - Ran all unit tests in
djblets.webapi.tests
with success.
Summary | ID |
---|---|
d39b84516abefb900321e80dd1d18f4524b0eb5d |
Description | From | Last Updated |
---|---|---|
SyntaxError: invalid syntax Column: 1 Error code: E999 |
reviewbot | |
Switch these two lines |
david | |
Instead of instantiating the registry as an attribute on this manager class, we shoud have a global within djblets. That … |
david | |
We should probably verify that this returns a value, and if not, raise WebAPITokenGenerationError. |
david | |
Can we swap these two args? That way all the query args are together. |
david | |
While you're here, can you move this import up into the 3rd party modules group? |
david | |
Let's put a Version Added in each of these new ones. Helps to have a high-level in the function's description, … |
chipx86 | |
No need for the parens here, or the trailing comma. |
chipx86 | |
No need for the parens here, or the trailing comma. |
chipx86 | |
No blank line here. |
chipx86 | |
Let's do import kgb and use attribute accesses from there. That's the pattern we've been establishing elsewhere. |
chipx86 | |
Can we also check the warning text, to ensure we're getting what we think we're getting? |
chipx86 | |
Let's move this after auto_generated. Since Python by default allows positional arguments to be specified for keyword arguments (unless using … |
chipx86 |
- Change Summary:
-
- Added deprecation warnings for when
token_generator_id
ortoken_info
aren't set.
- Added deprecation warnings for when
- Commits:
-
Summary ID 1bc481db2f099cc4127f48a2c3e6961a42bae5e0 6fe60bdab5c0235031d62e7a701f672cf524a7d9
- Change Summary:
-
Took out some stuff from patching in other changes that was left in by accident
- Commits:
-
Summary ID 6fe60bdab5c0235031d62e7a701f672cf524a7d9 de8050d5aefafacc856f48f45846d45666f2f59b
Checks run (2 succeeded)
-
-
-
Instead of instantiating the registry as an attribute on this manager class, we shoud have a global within djblets. That way extensions or other code can register additional generators easily.
This should live in
djblets/secrets/token_generators/__init__.py
and usedjblets.registries.importer.lazy_import_registry
. -
- Change Summary:
-
Uses the global token generator registry instead of making it an attribute of the manager class.
- Commits:
-
Summary ID de8050d5aefafacc856f48f45846d45666f2f59b 0f547dcb63b355db12cd6257b7a0b97d6e71f469
Checks run (2 succeeded)
- Change Summary:
-
Added methods for invalidating a token and a set of tokens to the manager.
- Commits:
-
Summary ID 0f547dcb63b355db12cd6257b7a0b97d6e71f469 9c8ee3d75c9ef6c9517c82c1b87f48bd57054487
Checks run (2 succeeded)
- Commits:
-
Summary ID 9c8ee3d75c9ef6c9517c82c1b87f48bd57054487 d7a8c2e918c57aadbacbaa0024943d937ee2ee73
Checks run (2 succeeded)
-
-
Let's move this after
auto_generated
. Since Python by default allows positional arguments to be specified for keyword arguments (unless using keyword-only arguments in Python 3), introducing a new argument in the middle is technically an API-breaking change.This is why I want to eventually move more things to keyword-only arguments (but that has its own deprecation challenges).