Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jupyter_drives/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def initialize(self, logger: logging.Logger, manager: JupyterDrivesManager):
@tornado.web.authenticated
async def get(self):
result = await self._manager.list_drives()
self.finish(result)
self.finish(json.dumps(result["data"]))

@tornado.web.authenticated
async def post(self):
Expand Down
11 changes: 5 additions & 6 deletions jupyter_drives/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,11 @@ async def list_drives(self):
results += drive.list_containers()

for result in results:
# in case of S3 drives get region of each drive
if self._config.provider == 's3':
location = self._get_drive_location(result.name)
data.append(
{
"name": result.name,
"region": location,
"creation_date": result.extra["creation_date"],
"region": self._config.region_name,
"creationDate": result.extra["creation_date"],
"mounted": False if result.name not in self._content_managers else True,
"provider": self._config.provider
}
Expand All @@ -141,7 +138,7 @@ async def list_drives(self):
}
return response

async def mount_drive(self, drive_name, provider, region):
async def mount_drive(self, drive_name, provider):
"""Mount a drive.

Args:
Expand All @@ -151,6 +148,8 @@ async def mount_drive(self, drive_name, provider, region):
# check if content manager doesn't already exist
if drive_name not in self._content_managers or self._content_managers[drive_name] is None:
if provider == 's3':
# get region of drive
region = self._get_drive_location(drive_name)
if self._config.session_token is None:
configuration = {
"aws_access_key_id": self._config.access_key_id,
Expand Down
2 changes: 1 addition & 1 deletion jupyter_drives/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def test_ListJupyterDrives_s3_empty_list(jp_fetch, s3_base):
# Then
assert response.code == 200
payload = json.loads(response.body)
assert len(payload["data"]) == 0
assert len(payload) == 0

@pytest.mark.skip(reason="FIX")
async def test_ListJupyterDrives_s3_missing_credentials(jp_fetch, s3_base):
Expand Down
3 changes: 1 addition & 2 deletions src/contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ export class Drive implements Contents.IDrive {
if (currentDrive.mounted === false) {
try {
await mountDrive(localPath, {
provider: currentDrive.provider,
region: currentDrive.region
provider: currentDrive.provider
});
this._drivesList.filter(x => x.name === localPath)[0].mounted = true;
} catch (e) {
Expand Down
13 changes: 2 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,9 @@ const drivesListProvider: JupyterFrontEndPlugin<IDriveInfo[]> = {
description: 'The drives list provider.',
provides: IDrivesList,
activate: async (_: JupyterFrontEnd): Promise<IDriveInfo[]> => {
const drives: IDriveInfo[] = [];
let drives: IDriveInfo[] = [];
try {
const response = await getDrivesList();
for (const drive of response.data) {
drives.push({
name: drive.name,
region: drive.region,
provider: drive.provider,
creationDate: drive.creation_date,
mounted: drive.mounted
});
}
drives = await getDrivesList();
} catch (error) {
console.log('Failed loading available drives list, with error: ', error);
}
Expand Down
15 changes: 9 additions & 6 deletions src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Contents } from '@jupyterlab/services';
import { PathExt } from '@jupyterlab/coreutils';

import { requestAPI } from './handler';
import { getFileType, IRegisteredFileTypes, IContentsList } from './token';
import {
getFileType,
IRegisteredFileTypes,
IContentsList,
IDriveInfo
} from './token';

/**
* The data contents model.
Expand Down Expand Up @@ -37,24 +42,22 @@ export async function setListingLimit(newLimit: number) {
* @returns The list of available drives.
*/
export async function getDrivesList() {
return await requestAPI<any>('drives', 'GET');
return await requestAPI<IDriveInfo[]>('drives', 'GET');
}

/**
* Mount a drive by establishing a connection with it.
*
* @param driveName
* @param options.provider The provider of the drive to be mounted.
* @param options.region The region of the drive to be mounted.
*/
export async function mountDrive(
driveName: string,
options: { provider: string; region: string }
options: { provider: string }
) {
const body: ReadonlyJSONObject = {
drive_name: driveName,
provider: options.provider,
region: options.region
provider: options.provider
};
return await requestAPI<any>('drives', 'POST', body);
}
Expand Down
Loading