Skip to content

Commit 7b4b2cf

Browse files
committed
backend function for adding public drives
1 parent 7e5396a commit 7b4b2cf

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

jupyter_drives/handlers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ async def post(self, drive: str = "", path: str = ""):
9191
body = self.get_json_body()
9292
if 'location' in body:
9393
result = await self._manager.new_drive(drive, **body)
94+
if 'public' in body:
95+
result = await self._manager.add_public_drive(drive)
9496
else:
9597
result = await self._manager.new_file(drive, path, **body)
9698
self.finish(result)

jupyter_drives/manager.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,17 @@ async def list_drives(self):
187187
results = []
188188
for drive in self._drives:
189189
try:
190-
results += drive.list_containers()
190+
if hasattr(drive, 'is_public'):
191+
results.append({
192+
"name": drive.url,
193+
"region": self._config.region_name,
194+
"creationDate": datetime.datetime.now(),
195+
"mounted": False if result.name not in self._content_managers else True,
196+
"provider": self._config.provider
197+
})
198+
else:
199+
results += drive.list_containers()
200+
191201
except Exception as e:
192202
raise tornado.web.HTTPError(
193203
status_code=httpx.codes.BAD_REQUEST,
@@ -624,6 +634,28 @@ async def new_drive(self, new_drive_name, location='us-east-1'):
624634

625635
return
626636

637+
async def add_public_drive(self, drive_url):
638+
"""Mount a drive.
639+
640+
Args:
641+
drive_url: public URL of bucket to mount
642+
"""
643+
try:
644+
drive = {
645+
"is_public": True,
646+
"url": drive_url
647+
};
648+
print('ADDED PUBLIC DRIVE: ', drive)
649+
self._drives.append(drive);
650+
print(self._drives)
651+
except Exception as e:
652+
raise tornado.web.HTTPError(
653+
status_code= httpx.codes.BAD_REQUEST,
654+
reason= f"The following error occured when adding the public drive: {e}"
655+
)
656+
657+
return
658+
627659
async def _get_drive_location(self, drive_name):
628660
"""Helping function for getting drive region.
629661

0 commit comments

Comments
 (0)