diff --git a/jupyter_drives/manager.py b/jupyter_drives/manager.py index 0063f86..6923523 100644 --- a/jupyter_drives/manager.py +++ b/jupyter_drives/manager.py @@ -319,6 +319,12 @@ async def mount_drive(self, drive_name, provider, location=''): else: region = await self._get_drive_location(drive_name) self._initialize_content_manager(drive_name, provider, region) + + # check if user is able to access drive + check = await self._file_system._exists(drive_name + '/') + if check is False: + raise Exception('Failed to mount drive. Access denied.') + except Exception as e: raise tornado.web.HTTPError( status_code= httpx.codes.BAD_REQUEST, diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 0613c03..2d3fe78 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -19,7 +19,8 @@ import { IToolbarWidgetRegistry, setToolbar, showDialog, - Dialog + Dialog, + Notification } from '@jupyterlab/apputils'; import { ISettingRegistry } from '@jupyterlab/settingregistry'; import { @@ -39,8 +40,9 @@ import { Widget } from '@lumino/widgets'; import { driveBrowserIcon, removeIcon } from '../icons'; import { Drive } from '../contents'; -import { getContents, setListingLimit } from '../requests'; +import { getContents, mountDrive, setListingLimit } from '../requests'; import { CommandIDs } from '../token'; +import { DrivesResponseError } from '../handler'; /** * Status bar widget for displaying drive information @@ -535,9 +537,23 @@ namespace Private { ariaLabel: 'Add Drive' }) ] - }).then(result => { + }).then(async result => { if (result.value) { - drive.addPublicDrive(result.value); + const response = await mountDrive(result.value, { + provider: 's3' + }); + if (response && response.error) { + // Show error in case of failure. + Notification.emit( + (response.error as DrivesResponseError).message, + 'error', + { + autoClose: 5000 + } + ); + } else { + drive.addPublicDrive(result.value); + } } }); }, @@ -567,9 +583,24 @@ namespace Private { ariaLabel: 'Add Drive' }) ] - }).then(result => { + }).then(async result => { if (result.value) { - drive.addExternalDrive(result.value[0], result.value[1]); + const response = await mountDrive(result.value[0], { + provider: 's3', + location: result.value[1] + }); + if (response && response.error) { + // Show error in case of failure. + Notification.emit( + (response.error as DrivesResponseError).message, + 'error', + { + autoClose: 5000 + } + ); + } else { + drive.addExternalDrive(result.value[0], result.value[1]); + } } }); },