Skip to content

Commit

Permalink
Only authenticate via gcloud if no access token is manually provided
Browse files Browse the repository at this point in the history
  • Loading branch information
hrjn committed Aug 27, 2024
1 parent 64f755a commit b7315e5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/mistralai_gcp/src/mistralai_gcp/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ def __init__(
:param async_client: The Async HTTP client to use for all asynchronous methods
:param retry_config: The retry configuration to use for all supported methods
"""

credentials, loaded_project_id = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
credentials.refresh(google.auth.transport.requests.Request())

if not isinstance(credentials, google.auth.credentials.Credentials):
raise models.SDKError(
"credentials must be an instance of google.auth.credentials.Credentials"
if not access_token:
credentials, loaded_project_id = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
credentials.refresh(google.auth.transport.requests.Request())

if not isinstance(credentials, google.auth.credentials.Credentials):
raise models.SDKError(
"credentials must be an instance of google.auth.credentials.Credentials"
)

project_id = project_id or loaded_project_id
if project_id is None:
Expand Down

0 comments on commit b7315e5

Please sign in to comment.