in python/pipelines/pipeline_ops.py [0:0]
def get_gcp_bearer_token() -> str:
"""
Retrieves a bearer token for Google Cloud Platform (GCP) authentication.
creds.valid is False, and creds.token is None
Need to refresh credentials to populate those
Returns:
A string containing the bearer token.
Raises:
Exception: If an error occurs while retrieving the bearer token.
"""
# Get the default credentials for the current environment.
creds, project = google.auth.default()
# Refresh the credentials to ensure they are valid.
creds.refresh(google.auth.transport.requests.Request())
# Extract the bearer token from the refreshed credentials.
bearer_token = creds.token
# Return the bearer token.
return bearer_token