-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
# 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 |
There was a problem hiding this comment.
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)
Migrated PR to googleapis/mcp-toolbox-sdk-python#18 |
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