Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(langchain-sdk): Update conftest to be able to run tests in local #222

Closed
wants to merge 4 commits into from

Conversation

twishabansal
Copy link
Contributor

@twishabansal twishabansal commented Jan 17, 2025

Getting an id token from metadata server does not work on local systems. This causes test failures for auth tests locally. This PR fixes the issue.

This unblocks https://b.corp.google.com/issues/385051620

@twishabansal twishabansal marked this pull request as ready for review January 17, 2025 07:18
@twishabansal twishabansal requested a review from a team as a code owner January 17, 2025 07:18
@twishabansal twishabansal enabled auto-merge (squash) January 17, 2025 07:21
@twishabansal twishabansal disabled auto-merge January 17, 2025 07:28
Comment on lines +84 to +101
# Try getting the token using gcloud (for local development)
result = subprocess.run(
["gcloud", "auth", "print-identity-token"],
capture_output=True,
text=True,
check=True,
)
return result.stdout.strip()
except (subprocess.CalledProcessError, FileNotFoundError):
request = google.auth.transport.requests.Request()
credentials = compute_engine.IDTokenCredentials(
request=request,
target_audience=client_id,
use_metadata_identity_endpoint=True,
)
if not credentials.valid:
credentials.refresh(request)
return credentials.token
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure I agree with this flow. I think ideally it should be trying the metadata server first, and falling back to gcloud if it's unable to reach. An alternative would be use an env var to signal which to use.

Ideally, we should not rely on "gcloud auth" as it's not semantically versioned (and I've personally been bit by it changing int the past)

@Yuan325 Yuan325 closed this Feb 5, 2025
@Yuan325
Copy link
Contributor

Yuan325 commented Feb 5, 2025

Migrated PR to googleapis/mcp-toolbox-sdk-python#18

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.

4 participants