From 53f60b9d73b51569793afa6fbdc5fbf8d09ba276 Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 4 Aug 2025 17:41:24 +0200 Subject: [PATCH 1/4] Fix bug in flow control statement --- jupyter_drives/handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_drives/handlers.py b/jupyter_drives/handlers.py index 509d695..c20f051 100644 --- a/jupyter_drives/handlers.py +++ b/jupyter_drives/handlers.py @@ -101,7 +101,7 @@ async def post(self, drive: str = "", path: str = ""): body = self.get_json_body() if 'location' in body: result = await self._manager.new_drive(drive, **body) - if 'public' in body: + elif 'public' in body: result = await self._manager.add_public_drive(drive) else: result = await self._manager.new_file(drive, path, **body) From 87c06ce18fbc2185c2449443f03baf6f0012f53d Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 4 Aug 2025 17:49:58 +0200 Subject: [PATCH 2/4] Don't pass us-east-1 as value during bucket creation --- jupyter_drives/manager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jupyter_drives/manager.py b/jupyter_drives/manager.py index f4fc6ca..373ee4f 100644 --- a/jupyter_drives/manager.py +++ b/jupyter_drives/manager.py @@ -695,7 +695,7 @@ async def check_file(self, drive_name, path): return - async def new_drive(self, new_drive_name, location='us-east-1'): + async def new_drive(self, new_drive_name, location): """Create a new drive in the given location. Args: @@ -703,7 +703,9 @@ async def new_drive(self, new_drive_name, location='us-east-1'): location: (optional) region of bucket """ try: - await self._file_system._mkdir(new_drive_name, region_name = location) + # AWS returns an error if the region is set to 'us-east-1' (Their default) + region_name = '' if location == 'us-east-1' else location + await self._file_system._mkdir(new_drive_name, region_name) except Exception as e: raise tornado.web.HTTPError( status_code= httpx.codes.BAD_REQUEST, From d8e3d0aff99e268fcef13ed9a26c851252b1ff7b Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 5 Aug 2025 17:48:44 +0200 Subject: [PATCH 3/4] Use boto3 client to create bucket --- jupyter_drives/manager.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/jupyter_drives/manager.py b/jupyter_drives/manager.py index 373ee4f..d0a567c 100644 --- a/jupyter_drives/manager.py +++ b/jupyter_drives/manager.py @@ -47,7 +47,9 @@ class JupyterDrivesManager(): It needs them to extract the ``DrivesConfig``. """ def __init__(self, config: traitlets.config.Config) -> None: + print("[DEBUG] JupyterDrivesManager.__init__() called11") self._config = DrivesConfig(config=config) + print("[DEBUG] JupyterDrivesManager.__init__() config loaded", self._config) self._client = httpx.AsyncClient() self._content_managers = {} self._max_files_listed = 1025 @@ -703,9 +705,24 @@ async def new_drive(self, new_drive_name, location): location: (optional) region of bucket """ try: - # AWS returns an error if the region is set to 'us-east-1' (Their default) - region_name = '' if location == 'us-east-1' else location - await self._file_system._mkdir(new_drive_name, region_name) + # Create a region-specific S3 client for bucket creation + # This ensures the client matches the target region + async with self._s3_session.create_client( + 's3', + aws_secret_access_key=self._config.secret_access_key, + aws_access_key_id=self._config.access_key_id, + aws_session_token=self._config.session_token, + region_name=location # Use the target region + ) as client: + if location == 'us-east-1': + # For us-east-1, don't specify location constraint + await client.create_bucket(Bucket=new_drive_name) + else: + # For other regions, specify the location constraint + await client.create_bucket( + Bucket=new_drive_name, + CreateBucketConfiguration={'LocationConstraint': location} + ) except Exception as e: raise tornado.web.HTTPError( status_code= httpx.codes.BAD_REQUEST, From 506b115a3b049ae83722edc6a5055d231f27ab40 Mon Sep 17 00:00:00 2001 From: Greg Date: Wed, 6 Aug 2025 11:22:33 +0200 Subject: [PATCH 4/4] Clean up --- jupyter_drives/manager.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jupyter_drives/manager.py b/jupyter_drives/manager.py index d0a567c..3aef4ea 100644 --- a/jupyter_drives/manager.py +++ b/jupyter_drives/manager.py @@ -47,9 +47,7 @@ class JupyterDrivesManager(): It needs them to extract the ``DrivesConfig``. """ def __init__(self, config: traitlets.config.Config) -> None: - print("[DEBUG] JupyterDrivesManager.__init__() called11") self._config = DrivesConfig(config=config) - print("[DEBUG] JupyterDrivesManager.__init__() config loaded", self._config) self._client = httpx.AsyncClient() self._content_managers = {} self._max_files_listed = 1025 @@ -699,20 +697,22 @@ async def check_file(self, drive_name, path): async def new_drive(self, new_drive_name, location): """Create a new drive in the given location. - + Args: new_drive_name: name of new drive to create location: (optional) region of bucket """ + location = location or 'us-east-1' + try: # Create a region-specific S3 client for bucket creation # This ensures the client matches the target region async with self._s3_session.create_client( - 's3', - aws_secret_access_key=self._config.secret_access_key, - aws_access_key_id=self._config.access_key_id, + 's3', + aws_secret_access_key=self._config.secret_access_key, + aws_access_key_id=self._config.access_key_id, aws_session_token=self._config.session_token, - region_name=location # Use the target region + region_name=location ) as client: if location == 'us-east-1': # For us-east-1, don't specify location constraint @@ -728,7 +728,7 @@ async def new_drive(self, new_drive_name, location): status_code= httpx.codes.BAD_REQUEST, reason=f"The following error occured when creating the new drive: {e}", ) - + return async def add_public_drive(self, drive_name):