Skip to content

Commit 398747a

Browse files
authored
Merge branch 'main' into external_drives
2 parents 026c61f + f00a6bb commit 398747a

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

jupyter_drives/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def post(self, drive: str = "", path: str = ""):
101101
body = self.get_json_body()
102102
if 'location' in body:
103103
result = await self._manager.new_drive(drive, **body)
104-
if 'is_public' in body:
104+
elif 'is_public' in body:
105105
result = await self._manager.add_external_drive(drive, **body)
106106
else:
107107
result = await self._manager.new_file(drive, path, **body)

jupyter_drives/manager.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,21 +698,40 @@ async def check_file(self, drive_name, path):
698698

699699
return
700700

701-
async def new_drive(self, new_drive_name, location='us-east-1'):
701+
async def new_drive(self, new_drive_name, location):
702702
"""Create a new drive in the given location.
703-
703+
704704
Args:
705705
new_drive_name: name of new drive to create
706706
location: (optional) region of bucket
707707
"""
708+
location = location or 'us-east-1'
709+
708710
try:
709-
await self._file_system._mkdir(new_drive_name, region_name = location)
711+
# Create a region-specific S3 client for bucket creation
712+
# This ensures the client matches the target region
713+
async with self._s3_session.create_client(
714+
's3',
715+
aws_secret_access_key=self._config.secret_access_key,
716+
aws_access_key_id=self._config.access_key_id,
717+
aws_session_token=self._config.session_token,
718+
region_name=location
719+
) as client:
720+
if location == 'us-east-1':
721+
# For us-east-1, don't specify location constraint
722+
await client.create_bucket(Bucket=new_drive_name)
723+
else:
724+
# For other regions, specify the location constraint
725+
await client.create_bucket(
726+
Bucket=new_drive_name,
727+
CreateBucketConfiguration={'LocationConstraint': location}
728+
)
710729
except Exception as e:
711730
raise tornado.web.HTTPError(
712731
status_code= httpx.codes.BAD_REQUEST,
713732
reason=f"The following error occured when creating the new drive: {e}",
714733
)
715-
734+
716735
return
717736

718737
async def add_external_drive(self, drive_name, is_public, region='us-east-1'):

0 commit comments

Comments
 (0)