Skip to content

Comments

patches call to indexclient#8

Open
bwalsh wants to merge 8 commits intodevelopmentfrom
feature/rbac
Open

patches call to indexclient#8
bwalsh wants to merge 8 commits intodevelopmentfrom
feature/rbac

Conversation

@bwalsh
Copy link
Collaborator

@bwalsh bwalsh commented Jul 22, 2025

TL/DR

This PR:

  • patches call to indexclient

🛠 PR #8: Monkey Patch IndexClient._get to Ensure Auth Header

🔍 Summary

This PR introduces a monkey patch to the IndexClient._get method in the indexclient Python library to ensure that every _get() request includes the required auth parameter. This patch helps prevent unauthenticated requests when the caller forgets to pass auth explicitly.


📚 Use Case

In the image_viewer application (or its backend), the IndexClient._get() method from the indexclient library is used to retrieve metadata from Gen3's Indexd service. However, the base method requires the caller to manually supply the auth parameter.

Forgetting to pass auth results in failed requests or hard-to-debug authentication issues. This monkey patch injects self.auth automatically if it's missing, ensuring consistent authenticated requests.


✅ Acceptance Criteria

  • Replace IndexClient._get with a wrapped version (patched__get) at runtime.
  • If the caller omits the auth keyword argument, set auth=self.auth automatically.
  • Maintain all existing behavior of _get when auth is provided.
  • Logically scoped and side-effect free outside the intended monkey patch.
  • Patch is applied during module load (monkey_patch_indexclient__get() is called at the end of the file).

🧪 Acceptance Tests

Manual verification steps:

  1. Without patch:

    • Call IndexClient._get(...) without auth=
    • Expect failure or 403 Unauthorized.
  2. With patch:

    • Call same method without auth=
    • Request succeeds using self.auth.
  3. Explicit auth override:

    • Call _get(..., auth=some_other_auth)
    • Confirm that some_other_auth is used, not self.auth.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a monkey patch for the IndexClient._get method from the indexclient library to automatically inject authentication parameters when they are missing from requests. The patch ensures that calls to _get() will use self.auth as a fallback when no explicit auth parameter is provided, preventing authentication failures due to missing credentials.

Key changes:

  • Implements a monkey patch function that wraps the original IndexClient._get method
  • Automatically sets auth=self.auth when the auth parameter is omitted from method calls
  • Applies the patch during module initialization


def patched__get(self, *args, **kwargs):
"""Patch to ensure 'auth' is set and log the call."""
if 'auth' not in kwargs:
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

The patch assumes that self.auth exists and is valid. Consider adding a check to ensure self.auth is not None before assigning it, or handle the case where it might not be available.

Suggested change
if 'auth' not in kwargs:
if 'auth' not in kwargs:
if self.auth is None:
raise ValueError("self.auth is not set. Ensure it is initialized before calling _get.")

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@matthewpeterkort matthewpeterkort left a comment

Choose a reason for hiding this comment

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

Working on development

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