Skip to content

refactor: allow any token retriever in the rest client - #1553

Merged
tpoliaw merged 6 commits into
mainfrom
service_account_client
Dec 3, 2026
Merged

tpoliaw merged 6 commits into
mainfrom
service_account_client

Conversation

@jacob-williamson

@jacob-williamson jacob-williamson commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Where previously the rest client required a session manager to handle retrieving auth tokens, it now accepts anything with a get_valid_access_token method, so a UDC client can use the same rest client.

@jacob-williamson
jacob-williamson requested a review from a team as a code owner June 10, 2026 13:19
@jacob-williamson jacob-williamson changed the title Don't require a session manager in the rest client refactor: allow any token retriever in the rest client Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.32%. Comparing base (a6d4a99) to head (429b7b4).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DominicOram DominicOram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@tpoliaw tpoliaw left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/blueapi/service/authentication.py Resolved
Comment thread src/blueapi/client/rest.py Outdated
class BlueapiRestClient:
_config: RestConfig
_session_manager: SessionManager | None
_token_retreiver: TokenRetriever | None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_token_retreiver: TokenRetriever | None
_token_retriever: TokenRetriever | None

Comment thread src/blueapi/service/authentication.py Outdated


class TokenRetriever(Protocol):
def get_valid_access_token(self) -> str: ...
@jacob-williamson

Copy link
Copy Markdown
Contributor Author

I've renamed to TokenSource and made SessionManager explicitly inherit from it. Can move the UDC token source over in a later PR

@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

if sm := self._rest.session_manager:
sm.logout()
self._rest.session_manager = None
if isinstance(self._rest.token_source, SessionManager):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should be

if hasattr(self._rest.token_source, "logout"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe but I think for now the instance check is ok

@tpoliaw
tpoliaw dismissed DominicOram’s stale review December 3, 2026 10:38

Code has changed since review. UDC token source can be added if required later

@tpoliaw
tpoliaw added this pull request to the merge queue Dec 3, 2026
Merged via the queue into main with commit b7c8cac Dec 3, 2026
21 checks passed
@tpoliaw
tpoliaw deleted the service_account_client branch December 3, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants