Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#10315]fix(client-python): Fix GCS credential handling for gcsfs 2026.2.0 compatibility (#10317)

geyanggang34938d52aff8
diff --git a/clients/client-python/gravitino/filesystem/gvfs_storage_handler.py b/clients/client-python/gravitino/filesystem/gvfs_storage_handler.py
index 63c215079a..22abc27aa9 100644
--- a/clients/client-python/gravitino/filesystem/gvfs_storage_handler.py
+++ b/clients/client-python/gravitino/filesystem/gvfs_storage_handler.py
@@ -19,6 +19,7 @@ import logging
import sys
import time
from abc import ABC, abstractmethod
+from datetime import datetime, timezone
from enum import Enum
from typing import Optional, Tuple, List, Dict, Any
@@ -40,6 +41,14 @@ from gravitino.api.credential.s3_token_credential import S3TokenCredential
from gravitino.exceptions.base import GravitinoRuntimeException
from gravitino.filesystem.gvfs_config import GVFSConfig
+try:
+ from google.auth.credentials import Credentials
+ from google.auth.exceptions import RefreshError
+
+ GOOGLE_AUTH_AVAILABLE = True
+except ImportError:
+ GOOGLE_AUTH_AVAILABLE = False
+
TIME_WITHOUT_EXPIRATION = sys.maxsize
SLASH = "/"
@@ -403,10 +412,50 @@ class GCSStorageHandler(StorageHandler):
catalog_props,
)
if isinstance(credential, GCSTokenCredential):
+ if not GOOGLE_AUTH_AVAILABLE:
+ raise GravitinoRuntimeException(
+ "Failed to import google.auth. "
+ "Please ensure google-auth is installed."
+ )
+
+ # gcsfs expects a google.auth.credentials.Credentials object
+ # We need to create a credentials object from the access token
+ class StaticCredentials(Credentials):
+ """A credentials object that uses a static access token."""
+
+ def __init__(self, token_value, expiry_time_ms):
+ super().__init__()
+ self.token = token_value
+ # Convert milliseconds to datetime
+ self.expiry = datetime.fromtimestamp(
+ expiry_time_ms / 1000.0, tz=timezone.utc
+ )
+
+ def refresh(self, request):
+ # Static token cannot be refreshed
+ raise RefreshError(
+ "Cannot refresh static access token. "
+ "Please request a new credential from Gravitino."
+ )
+
+ @property
+ def expired(self):
+ if not self.expiry:
+ return False
+ return datetime.now(timezone.utc) >= self.expiry
+
+ @property
+ def valid(self):
+ return self.token is not None and not self.expired
+
+ creds = StaticCredentials(
+ credential.token(), credential.expire_time_in_ms()
+ )
+
return (
expire_time,
self.get_filesystem(
- token=credential.token(),
+ token=creds,
**kwargs,
),
)