mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-29 00:48:01 -05:00
refactor(gcs): remove unused GCSClientManager class
Dead code that was never integrated. The codebase uses download_with_fresh_session and generate_signed_url functions instead, and GCSWorkspaceStorage has its own client management. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,8 +8,6 @@ including path parsing, client management, and signed URL generation.
|
||||
import asyncio
|
||||
import logging
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Optional
|
||||
|
||||
import aiohttp
|
||||
from gcloud.aio import storage as async_gcs_storage
|
||||
from google.cloud import storage as gcs_storage
|
||||
@@ -41,62 +39,6 @@ def parse_gcs_path(path: str) -> tuple[str, str]:
|
||||
return parts[0], parts[1]
|
||||
|
||||
|
||||
class GCSClientManager:
|
||||
"""
|
||||
Manages async and sync GCS clients with lazy initialization.
|
||||
|
||||
This class provides a unified way to manage GCS client lifecycle,
|
||||
supporting both async operations (uploads, downloads) and sync
|
||||
operations that require service account credentials (signed URLs).
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._async_client: Optional[async_gcs_storage.Storage] = None
|
||||
self._sync_client: Optional[gcs_storage.Client] = None
|
||||
self._session: Optional[aiohttp.ClientSession] = None
|
||||
|
||||
async def get_async_client(self) -> async_gcs_storage.Storage:
|
||||
"""
|
||||
Get or create async GCS client.
|
||||
|
||||
Returns:
|
||||
Async GCS storage client
|
||||
"""
|
||||
if self._async_client is None:
|
||||
self._session = aiohttp.ClientSession(
|
||||
connector=aiohttp.TCPConnector(limit=100, force_close=False)
|
||||
)
|
||||
self._async_client = async_gcs_storage.Storage(session=self._session)
|
||||
return self._async_client
|
||||
|
||||
def get_sync_client(self) -> gcs_storage.Client:
|
||||
"""
|
||||
Get or create sync GCS client (used for signed URLs).
|
||||
|
||||
Returns:
|
||||
Sync GCS storage client
|
||||
"""
|
||||
if self._sync_client is None:
|
||||
self._sync_client = gcs_storage.Client()
|
||||
return self._sync_client
|
||||
|
||||
async def close(self) -> None:
|
||||
"""Close all client connections."""
|
||||
if self._async_client is not None:
|
||||
try:
|
||||
await self._async_client.close()
|
||||
except Exception as e:
|
||||
logger.warning(f"Error closing GCS client: {e}")
|
||||
self._async_client = None
|
||||
|
||||
if self._session is not None:
|
||||
try:
|
||||
await self._session.close()
|
||||
except Exception as e:
|
||||
logger.warning(f"Error closing session: {e}")
|
||||
self._session = None
|
||||
|
||||
|
||||
async def download_with_fresh_session(bucket: str, blob: str) -> bytes:
|
||||
"""
|
||||
Download file content using a fresh session.
|
||||
|
||||
Reference in New Issue
Block a user