Skip to content

Per request auth#123

Merged
pbrassel merged 4 commits into
mainfrom
per-request-auth
Jul 23, 2026
Merged

Per request auth#123
pbrassel merged 4 commits into
mainfrom
per-request-auth

Conversation

@pbrassel

@pbrassel pbrassel commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added support for overriding authentication on individual requests.
    • Added static bearer-token authentication for clients and requests.
    • Expanded endpoint methods to accept per-request options consistently.
    • Improved streaming and upload request handling.
  • Bug Fixes

    • Standardized HTTP error handling across client operations.
  • Documentation

    • Documented per-request authentication options.
    • Updated the code coverage badge from 95% to 97%.

pbrassel added 2 commits July 23, 2026 10:29
Add an optional `auth` parameter to every public client method to override authentication for a single request. Change logic how parameters are passed through, so that it is easier to add more parameters without changing every method definition.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@pbrassel, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 911a3d71-ac34-4ee3-bdb7-83a961947c0f

📥 Commits

Reviewing files that changed from the base of the PR and between cccf1b8 and 3b8b42b.

📒 Files selected for processing (3)
  • docs/user_guide.rst
  • flame_hub/_base_client.py
  • tests/test_storage.py
📝 Walkthrough

Walkthrough

The client library adds static bearer-token authentication, supports per-request authentication overrides, centralizes HTTP status handling, and forwards shared request parameters across auth, core, and storage clients. Tests and user documentation cover the new authentication behavior.

Changes

Authentication and request flow

Layer / File(s) Summary
Authentication contracts and static auth
flame_hub/_auth_flows.py, flame_hub/_base_client.py, flame_hub/auth.py, flame_hub/types.py
Adds StaticAuth, AuthParam, BaseKwargs, resolve_auth(), and public exports for static tokens and shared request types.
Centralized request pipeline
flame_hub/_base_client.py
Routes resource operations through _request, resolves per-request authentication, enforces expected status codes, and preserves 404 handling.
AuthClient and CoreClient forwarding
flame_hub/_auth_client.py, flame_hub/_core_client.py
Adds shared request-parameter forwarding across mutation, credential, command, and deletion endpoints.
Storage request and streaming flow
flame_hub/_storage_client.py
Uses centralized request handling for uploads, downloads, and bucket operations while closing streamed responses.
Authentication validation and documentation
tests/test_base_client.py, tests/test_flow.py, docs/user_guide.rst, README.md
Tests static authentication and per-request overrides, documents authentication options, and updates the coverage badge.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant CoreClient
  participant BaseClient
  participant HTTPClient
  Caller->>CoreClient: invoke endpoint with auth override
  CoreClient->>BaseClient: forward BaseKwargs
  BaseClient->>HTTPClient: send request with resolved auth
  HTTPClient-->>BaseClient: response
  BaseClient-->>CoreClient: model or HubAPIError
  CoreClient-->>Caller: endpoint result
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding per-request authentication overrides.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch per-request-auth

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
flame_hub/_core_client.py (1)

680-693: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Missing return type annotation on update_project_node.

Every sibling update_* method in this file (update_node, update_analysis, update_analysis_node, update_registry, update_registry_project, update_client, etc.) declares -> ResourceType, but this signature closes with a bare ): even though it returns self._update_resource(...), which resolves to ProjectNode.

🔧 Proposed fix
     def update_project_node(
         self,
         project_node_id: ProjectNode | uuid.UUID | str,
         comment: str | None | UNSET_T = UNSET,
         approval_status: ProjectNodeApprovalStatus | None | UNSET_T = UNSET,
         **params: te.Unpack[BaseKwargs],
-    ):
+    ) -> ProjectNode:
         return self._update_resource(
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@flame_hub/_core_client.py` around lines 680 - 693, Add the missing return
type annotation to update_project_node, declaring that it returns ProjectNode,
consistent with the sibling update_* methods and the value returned by
_update_resource.
flame_hub/_base_client.py (1)

668-705: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

404-to-None detection now depends on the response body parsing successfully, regressing from raw status-code checking.

Per the diff summary, this previously returned None based on the raw HTTP status. Now it only returns None when e.error_response is not None and e.error_response.status_code == 404. new_hub_api_error_from_response leaves error_response as None whenever r.json()/ErrorResponse(**r.json()) raises ValidationError/JSONDecodeError (empty body, non-JSON body, or a body that doesn't validate as ErrorResponse — e.g. a generic 404 page from a misconfigured base_url or reverse proxy). In that case this method incorrectly re-raises instead of returning None, even though the actual HTTP status was 404.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@flame_hub/_base_client.py` around lines 668 - 705, Update the 404 handling in
the resource lookup method around the _request call so it checks the raw HTTP
response status when HubAPIError.error_response is unavailable, preserving the
existing return-None behavior for every 404 response regardless of response-body
parsing. Continue re-raising non-404 errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/user_guide.rst`:
- Around line 330-356: Update the PasswordAuth example in the “Overriding
authentication per request” section to use the documented qualified
authentication symbol, such as flame_hub.auth.PasswordAuth, consistent with the
other examples and available imports. Keep the request-specific authentication
behavior unchanged.

In `@flame_hub/_base_client.py`:
- Around line 438-492: Update _request to handle non-expected streamed responses
before calling new_hub_api_error_from_response: read the response body as needed
so error parsing cannot raise ResponseNotRead, and ensure the response is closed
on this error path. Preserve raising HubAPIError for all status mismatches,
including requests made by stream_bucket_tarball and stream_bucket_file.

---

Outside diff comments:
In `@flame_hub/_base_client.py`:
- Around line 668-705: Update the 404 handling in the resource lookup method
around the _request call so it checks the raw HTTP response status when
HubAPIError.error_response is unavailable, preserving the existing return-None
behavior for every 404 response regardless of response-body parsing. Continue
re-raising non-404 errors.

In `@flame_hub/_core_client.py`:
- Around line 680-693: Add the missing return type annotation to
update_project_node, declaring that it returns ProjectNode, consistent with the
sibling update_* methods and the value returned by _update_resource.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 60747e13-4dda-49a1-aca1-b3ff45a75d90

📥 Commits

Reviewing files that changed from the base of the PR and between 85b72c8 and cccf1b8.

📒 Files selected for processing (11)
  • README.md
  • docs/user_guide.rst
  • flame_hub/_auth_client.py
  • flame_hub/_auth_flows.py
  • flame_hub/_base_client.py
  • flame_hub/_core_client.py
  • flame_hub/_storage_client.py
  • flame_hub/auth.py
  • flame_hub/types.py
  • tests/test_base_client.py
  • tests/test_flow.py

Comment thread docs/user_guide.rst
Comment thread flame_hub/_base_client.py
pbrassel added 2 commits July 23, 2026 11:51
…status code

Since `new_hub_api_error_from_response()` calls `r.json()`, the response must be read beforehand otherwise a `httpx.ResponseNotRead` is being raised.
@pbrassel
pbrassel merged commit c9684d4 into main Jul 23, 2026
7 checks passed
@pbrassel
pbrassel deleted the per-request-auth branch July 23, 2026 10:10
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