Repository navigation
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 96.32% 96.32%
=======================================
Files 50 50
Lines 3833 3834 +1
=======================================
+ Hits 3692 3693 +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 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 |
|
|
||
|
|
||
| class TokenRetriever(Protocol): | ||
| def get_valid_access_token(self) -> str: ... |
|
I've renamed to |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
| if sm := self._rest.session_manager: | ||
| sm.logout() | ||
| self._rest.session_manager = None | ||
| if isinstance(self._rest.token_source, SessionManager): |
There was a problem hiding this comment.
Maybe should be
if hasattr(self._rest.token_source, "logout"):There was a problem hiding this comment.
Maybe but I think for now the instance check is ok
| if sm := self._rest.session_manager: | ||
| sm.logout() | ||
| self._rest.session_manager = None | ||
| if isinstance(self._rest.token_source, SessionManager): |
There was a problem hiding this comment.
Maybe but I think for now the instance check is ok
Code has changed since review. UDC token source can be added if required later
Where previously the rest client required a session manager to handle retrieving auth tokens, it now accepts anything with a
get_valid_access_tokenmethod, so a UDC client can use the same rest client.