Skip to content

Commit c7a824f

Browse files
authored
Merge pull request #48 from DenisaCG/fixRefresh
Get drive location when mounting
2 parents 31f2030 + 3711a67 commit c7a824f

File tree

6 files changed

+19
-27
lines changed

6 files changed

+19
-27
lines changed

jupyter_drives/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def initialize(self, logger: logging.Logger, manager: JupyterDrivesManager):
6666
@tornado.web.authenticated
6767
async def get(self):
6868
result = await self._manager.list_drives()
69-
self.finish(result)
69+
self.finish(json.dumps(result["data"]))
7070

7171
@tornado.web.authenticated
7272
async def post(self):

jupyter_drives/manager.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,11 @@ async def list_drives(self):
118118
results += drive.list_containers()
119119

120120
for result in results:
121-
# in case of S3 drives get region of each drive
122-
if self._config.provider == 's3':
123-
location = self._get_drive_location(result.name)
124121
data.append(
125122
{
126123
"name": result.name,
127-
"region": location,
128-
"creation_date": result.extra["creation_date"],
124+
"region": self._config.region_name,
125+
"creationDate": result.extra["creation_date"],
129126
"mounted": False if result.name not in self._content_managers else True,
130127
"provider": self._config.provider
131128
}
@@ -141,7 +138,7 @@ async def list_drives(self):
141138
}
142139
return response
143140

144-
async def mount_drive(self, drive_name, provider, region):
141+
async def mount_drive(self, drive_name, provider):
145142
"""Mount a drive.
146143
147144
Args:
@@ -151,6 +148,8 @@ async def mount_drive(self, drive_name, provider, region):
151148
# check if content manager doesn't already exist
152149
if drive_name not in self._content_managers or self._content_managers[drive_name] is None:
153150
if provider == 's3':
151+
# get region of drive
152+
region = self._get_drive_location(drive_name)
154153
if self._config.session_token is None:
155154
configuration = {
156155
"aws_access_key_id": self._config.access_key_id,

jupyter_drives/tests/test_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async def test_ListJupyterDrives_s3_empty_list(jp_fetch, s3_base):
5656
# Then
5757
assert response.code == 200
5858
payload = json.loads(response.body)
59-
assert len(payload["data"]) == 0
59+
assert len(payload) == 0
6060

6161
@pytest.mark.skip(reason="FIX")
6262
async def test_ListJupyterDrives_s3_missing_credentials(jp_fetch, s3_base):

src/contents.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ export class Drive implements Contents.IDrive {
229229
if (currentDrive.mounted === false) {
230230
try {
231231
await mountDrive(localPath, {
232-
provider: currentDrive.provider,
233-
region: currentDrive.region
232+
provider: currentDrive.provider
234233
});
235234
this._drivesList.filter(x => x.name === localPath)[0].mounted = true;
236235
} catch (e) {

src/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,9 @@ const drivesListProvider: JupyterFrontEndPlugin<IDriveInfo[]> = {
160160
description: 'The drives list provider.',
161161
provides: IDrivesList,
162162
activate: async (_: JupyterFrontEnd): Promise<IDriveInfo[]> => {
163-
const drives: IDriveInfo[] = [];
163+
let drives: IDriveInfo[] = [];
164164
try {
165-
const response = await getDrivesList();
166-
for (const drive of response.data) {
167-
drives.push({
168-
name: drive.name,
169-
region: drive.region,
170-
provider: drive.provider,
171-
creationDate: drive.creation_date,
172-
mounted: drive.mounted
173-
});
174-
}
165+
drives = await getDrivesList();
175166
} catch (error) {
176167
console.log('Failed loading available drives list, with error: ', error);
177168
}

src/requests.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { Contents } from '@jupyterlab/services';
33
import { PathExt } from '@jupyterlab/coreutils';
44

55
import { requestAPI } from './handler';
6-
import { getFileType, IRegisteredFileTypes, IContentsList } from './token';
6+
import {
7+
getFileType,
8+
IRegisteredFileTypes,
9+
IContentsList,
10+
IDriveInfo
11+
} from './token';
712

813
/**
914
* The data contents model.
@@ -37,24 +42,22 @@ export async function setListingLimit(newLimit: number) {
3742
* @returns The list of available drives.
3843
*/
3944
export async function getDrivesList() {
40-
return await requestAPI<any>('drives', 'GET');
45+
return await requestAPI<IDriveInfo[]>('drives', 'GET');
4146
}
4247

4348
/**
4449
* Mount a drive by establishing a connection with it.
4550
*
4651
* @param driveName
4752
* @param options.provider The provider of the drive to be mounted.
48-
* @param options.region The region of the drive to be mounted.
4953
*/
5054
export async function mountDrive(
5155
driveName: string,
52-
options: { provider: string; region: string }
56+
options: { provider: string }
5357
) {
5458
const body: ReadonlyJSONObject = {
5559
drive_name: driveName,
56-
provider: options.provider,
57-
region: options.region
60+
provider: options.provider
5861
};
5962
return await requestAPI<any>('drives', 'POST', body);
6063
}

0 commit comments

Comments
 (0)