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) diff --git a/jupyter_drives/manager.py b/jupyter_drives/manager.py index f4fc6ca..3aef4ea 100644 --- a/jupyter_drives/manager.py +++ b/jupyter_drives/manager.py @@ -695,21 +695,40 @@ 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: new_drive_name: name of new drive to create location: (optional) region of bucket """ + location = location or 'us-east-1' + try: - await self._file_system._mkdir(new_drive_name, region_name = location) + # 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 + ) 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, reason=f"The following error occured when creating the new drive: {e}", ) - + return async def add_public_drive(self, drive_name):