Skip to content

fix: make provider requests overridable - #485

Merged
anuragxxd merged 2 commits into
devfrom
fix/overridable-provider-fetch
Oct 27, 2026
Merged

anuragxxd merged 2 commits into
devfrom
fix/overridable-provider-fetch

Conversation

@anuragxxd

@anuragxxd anuragxxd commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Description

The REST providers called the global fetch() directly, so the authentication examples in the docs (subclass the provider and override fetch()) had no effect: requests went out without the added headers, and without an error.

  • All Rest*Provider classes now send every request through a protected fetch(input, init) method, which calls the global fetch() by default. Subclasses can override it to add headers such as Authorization. RestWesProvider.baseUrl is now protected instead of private, like the public baseUrl of the other providers.
  • Default behaviour is unchanged.
  • Docs: rewrote "Authentication Patterns" in docs/providers.mdx. The old examples relied on the missing fetch(), used a wrapper class nothing called, fetched the token only once, forced Content-Type: application/json (which would break the WES multipart upload) and passed a function as a header value. The per-package "Custom Providers" examples now work as written and are unchanged.
  • Tests: rest-wes-provider.test.ts checks that all 6 WES methods go through an overridden fetch(), that requests without an override carry no headers, and that the workflow upload stays multipart. Adds the test script to @elixir-cloud/wes.

This makes authenticated requests possible for the v2 packages without per-component token properties. Part of #442; TES still needs #443.

How it was verified

  • npm run lint: 0 errors, no new warnings.
  • npm run build, including the docs site.
  • npm test: 3/3 in Chromium, Firefox and WebKit. With one WES call switched back to the global fetch(), the override test fails.

Checklist

  • My code follows the contributing guidelines of this project.
  • I am aware that all my commits will be squashed into a single commit, using the PR title as the commit message.
  • I have performed a self-review of my own code.
  • I have commented my code in hard-to-understand areas.
  • I have updated the user-facing documentation to describe any new or changed behavior.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have not reduced the existing code coverage.

Comments

Tests cover WES only; the other providers got the same mechanical change.

Summary by Sourcery

Make REST provider requests overridable so applications can add authentication and other request customization without changing provider behavior by default.

New Features:

  • Enable subclasses of all REST providers to customize every outgoing request through an overridable protected fetch method, including authentication headers.

Bug Fixes:

  • Fix REST provider authentication examples so overridden request handling is actually used while preserving existing default behavior and multipart workflow uploads.

Enhancements:

  • Expose RestWesProvider.baseUrl to subclasses and update authentication documentation with working API-key, bearer-token, and custom-header patterns.

Documentation:

  • Rewrite the authentication guidance to support per-request tokens, valid header values, and uploads that rely on browser-managed multipart boundaries.

Tests:

  • Add WES provider coverage verifying all methods use the overridable fetch method, default requests remain header-free, and workflow uploads remain multipart.

Route every request of the REST providers through a protected fetch()
method, so that subclasses can add headers such as Authorization. The
documented auth examples overrode fetch(), which the providers never
called.

Also fix the authentication examples in the providers docs and add WES
provider tests.
@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR restores the documented authentication pattern by routing all REST provider requests through an overridable protected fetch method, preserving default behavior and multipart uploads. Documentation now demonstrates usable authentication/custom-header implementations, and WES tests verify complete hook coverage and request semantics.

Sequence diagram for overridable authenticated provider requests

sequenceDiagram
    participant App
    participant Provider as RestWesProviderSubclass
    participant FetchHook as fetch
    participant Network as API

    App->>Provider: getServiceInfo()
    Provider->>FetchHook: fetch(input, init)
    FetchHook->>FetchHook: Add current Authorization header
    FetchHook->>Network: global fetch(input, init)
    Network-->>FetchHook: Response
    FetchHook-->>Provider: Response
    Provider-->>App: ServiceInfo
Loading

Flow diagram for preserving WES multipart uploads

flowchart LR
    A["runWorkflow()"] --> B[Create FormData]
    B --> C["Overridden fetch(input, init)"]
    C --> D[Add authentication headers]
    D --> E[global fetch]
    E --> F[Browser sets multipart Content-Type]
Loading

File-Level Changes

Change Details Files
Introduced a protected request hook across REST providers so subclasses can customize every outbound request while retaining the global fetch implementation by default.
  • Added protected fetch(input, init) methods delegating to global fetch.
  • Replaced direct fetch calls across service registry, DRS, TRS, and WES operations with the provider hook.
  • Made WES baseUrl protected for subclass access.
packages/ecc-client-elixir-cloud-registry/src/providers/rest-cr-provider.ts
packages/ecc-client-elixir-drs-filer/src/providers/rest-drs-filer-provider.ts
packages/ecc-client-elixir-trs-filer/src/providers/rest-trs-filer-provider.ts
packages/ecc-client-ga4gh-drs/src/providers/rest-drs-provider.ts
packages/ecc-client-ga4gh-service-registry/src/providers/rest-sr-provider.ts
packages/ecc-client-ga4gh-trs/src/providers/rest-trs-provider.ts
packages/ecc-client-ga4gh-wes/src/providers/rest-wes-provider.ts
Reworked authentication guidance to use provider subclassing or wrappers that add request headers at call time without interfering with provider-managed content types.
  • Added working API-key, bearer-token, and dynamic custom-header examples.
  • Documented per-request token/header construction and multipart upload constraints.
  • Removed obsolete wrapper patterns and invalid header usage.
apps/documentation/pages/docs/providers.mdx
Added focused WES coverage for request overridability and upload behavior.
  • Verified all six WES methods use an overridden fetch hook.
  • Verified default requests remain header-free.
  • Verified authenticated workflow uploads retain FormData and omit Content-Type.
packages/ecc-client-ga4gh-wes/src/providers/tests/rest-wes-provider.test.ts
packages/ecc-client-ga4gh-wes/package.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

read-the-docs-community Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cloud-components | 🛠️ Build #35442808 | 📁 Comparing 9708e37 against latest (7eb87cc)

  🔍 Preview build  

1 file changed
± docs/providers/index.html

@anuragxxd
anuragxxd marked this pull request as ready for review October 27, 2026 13:13

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="apps/documentation/pages/docs/providers.mdx" line_range="153-154" />
<code_context>
-    });
+  fetch(input, init = {}) {
+    const headers = new Headers(init.headers);
+    headers.set('X-API-Key', this.apiKey);
+    return super.fetch(input, { ...init, headers });
   }
 }
</code_context>
<issue_to_address>
**API keys leak through redirects**

When an authenticated endpoint responds with a redirect to an attacker-controlled cross-origin URL, the browser follows the redirect and forwards custom headers such as `X-API-Key` to the destination, which lets that host capture credentials and impersonate the caller.

For requests carrying credentials, prevent automatic cross-origin redirects or ensure credential headers are removed before following them.

Also at `packages/ecc-client-elixir-cloud-registry/src/providers/rest-cr-provider.ts:24`, `packages/ecc-client-elixir-drs-filer/src/providers/rest-drs-filer-provider.ts:24`, `packages/ecc-client-elixir-trs-filer/src/providers/rest-trs-filer-provider.ts:28`, `packages/ecc-client-ga4gh-drs/src/providers/rest-drs-provider.ts:17`, `packages/ecc-client-ga4gh-service-registry/src/providers/rest-sr-provider.ts:22`, `packages/ecc-client-ga4gh-trs/src/providers/rest-trs-provider.ts:25`, `packages/ecc-client-ga4gh-wes/src/providers/rest-wes-provider.ts:29`.
</issue_to_address>

### Comment 2
<location path="apps/documentation/pages/docs/providers.mdx" line_range="136" />
<code_context>

 ### Authentication Patterns

+Components don't handle authentication; your app does. Every REST provider sends all of its requests through a `fetch(input, init)` method. Override it in a subclass to add headers such as `Authorization`, so you can use any auth flow (OAuth/OIDC, API keys, ...). You can also implement the provider interface yourself.
+
+<Callout type='warning'>
</code_context>
<issue_to_address>
**TES requests lose authentication headers**

When a consumer applies the documented authentication guidance to TES requests, `fetchService`, `fetchTasks`, and `tesGet` call global `fetch` instead of the documented provider override, so TES requests omit the added headers and protected endpoints return authorization failures rather than data.

Route TES API calls through the overridable provider `fetch` method.
</issue_to_address>

### Comment 3
<location path="packages/ecc-client-ga4gh-wes/src/providers/rest-wes-provider.ts" line_range="114" />
<code_context>
     const encodedObjectId = encodeURIComponent(objectId);
     const encodedAccessId = encodeURIComponent(accessId);
-    const response = await fetch(
+    const response = await this.fetch(
       `${this.baseUrl}/objects/${encodedObjectId}/access/${encodedAccessId}`
     );
</code_context>
<issue_to_address>
**URL-backed WES logs omit auth**

When a WES run log contains an HTTP(S) stdout or stderr URL that requires the same authentication as the WES API, `getRunLog` retrieves the log metadata through the override, but `ECCClientGa4ghWesRun.fetchLogUrlToCache` then uses global `fetch` for URL-valued stdout/stderr without the override’s headers, so protected logs fail to load in the component.

Route URL-backed log retrieval through an authenticated request path supplied by the provider, or otherwise provide the component with the credentials needed for that request.
</issue_to_address>

Sourcery assessment

Approval pending. 3 findings to address first.

Blocking findings: apps/documentation/pages/docs/providers.mdx:154, apps/documentation/pages/docs/providers.mdx:136, packages/ecc-client-ga4gh-wes/src/providers/rest-wes-provider.ts:114


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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.

1 participant