Skip to content

feat(client): Accept optional tokens in ClientBuilder::token#516

Open
jan-auer wants to merge 1 commit into
mainfrom
feat/token-optional
Open

feat(client): Accept optional tokens in ClientBuilder::token#516
jan-auer wants to merge 1 commit into
mainfrom
feat/token-optional

Conversation

@jan-auer

@jan-auer jan-auer commented Jun 23, 2026

Copy link
Copy Markdown
Member

The Client builder supports chaining methods. However, there was no way to conditionally supply a token generator while chaining builder methods, which is unergonomic.

ClientBuilder::token now accepts an Option directly via a new IntoTokenProvider trait. A None leaves the client unauthenticated. The new trait is also implemented for all types that were accepted previously, keeping backwards compatibility.

This brings the Rust client in line with the Python client, which already accepts an optional token:

// before
let mut builder = Client::builder(remote);
if let Some(token) = token_opt {
    builder = builder.token(token);
}
let client = builder.build()?;

// after
let client = Client::builder(remote)
    .token(token_opt)
    .build()?;

Callers that hold an optional token previously had to guard the builder
call, conditionally invoking `.token()` only when a value was present.

Introduce an `IntoTokenProvider` trait, implemented for `TokenGenerator`,
`String`, `&str`, and any `Option` of those. `ClientBuilder::token` now
accepts an `Option` directly, leaving the client unauthenticated on `None`,
so optional authentication needs no surrounding conditional.
@jan-auer jan-auer requested a review from a team as a code owner June 23, 2026 14:11
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.41%. Comparing base (2cc842a) to head (d1214c7).

Files with missing lines Patch % Lines
clients/rust/src/auth.rs 77.77% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #516   +/-   ##
=======================================
  Coverage   87.40%   87.41%           
=======================================
  Files          86       86           
  Lines       13893    13892    -1     
=======================================
  Hits        12143    12143           
+ Misses       1750     1749    -1     
Components Coverage Δ
Rust Backend 92.28% <ø> (ø)
Rust Client 80.07% <81.81%> (+0.04%) ⬆️
Python Client 88.51% <ø> (ø)

☔ 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.

@lcian lcian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

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.

2 participants