refactor: allow any token retriever in the rest client#1553
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1553 +/- ##
=======================================
Coverage 95.61% 95.61%
=======================================
Files 43 43
Lines 3214 3215 +1
=======================================
+ Hits 3073 3074 +1
Misses 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
DominicOram
left a comment
There was a problem hiding this comment.
Thanks, I think we want SessionManager to explicitly implement TokenRetriever though, right?
I also think we should add the UDCTokenRetriever (from https://github.com/DiamondLightSource/daq-queuing-service/pull/40/changes) into BlueAPI proper, it seems like a reasonable thing to have in here. Though maybe @tpoliaw disagrees?
There was a problem hiding this comment.
Thanks - this makes things simpler and should help when we come to refactor the login stuff in #1381.
Possibly a bit picky but can the protocol be called TokenSource or TokenProvider or similar. It's not really retrieving it if it's generating a new one and blueapi shouldn't care where it comes from.
I think we want SessionManager to explicitly implement TokenRetriever though, right?
It can do but I don't think it needs to.
I also think we should add the UDCTokenRetriever into BlueAPI proper
I'm not against the UDC ServiceAccount provider being in blueapi core but it doesn't need to be in this PR.
|
|
||
| class JWTAuth(AuthBase): | ||
| def __init__(self, session_manager: SessionManager | None): | ||
| def __init__(self, session_manager: TokenRetriever | None): |
There was a problem hiding this comment.
| def __init__(self, session_manager: TokenRetriever | None): | |
| def __init__(self, token_source: TokenRetriever | None): |
| class BlueapiRestClient: | ||
| _config: RestConfig | ||
| _session_manager: SessionManager | None | ||
| _token_retreiver: TokenRetriever | None |
There was a problem hiding this comment.
| _token_retreiver: TokenRetriever | None | |
| _token_retriever: TokenRetriever | None |
See https://confluence.diamond.ac.uk/pages/viewpage.action?pageId=398853592&spaceKey=DCT&title=04-06-2026
Currently the rest client requires a session manager to handle retrieving auth tokens. I've made it more flexible so that it now accepts anything with a
get_valid_access_tokenmethod, so a UDC client can use the same rest client.