Skip to content

Commit 5165ae0

Browse files
committed
fix mount drives and refresh drive content managers
1 parent 5100784 commit 5165ae0

File tree

2 files changed

+45
-38
lines changed

2 files changed

+45
-38
lines changed

jupyter_drives/manager.py

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def _drives_refresh_callback(self):
8989
self._config.load_credentials()
9090
self._initialize_s3_file_system()
9191
self._initialize_drives()
92+
self._initialize_content_managers()
9293

9394
def _initialize_s3_file_system(self):
9495
# initiate aiobotocore session if we are dealing with S3 drives
@@ -116,6 +117,43 @@ def _initialize_drives(self):
116117
GCSDrive = get_driver(Provider.GOOGLE_STORAGE)
117118
self._drives = [GCSDrive(self._config.access_key_id, self._config.secret_access_key)] # verfiy credentials needed
118119

120+
def _initialize_content_managers(self):
121+
for drive_name, content_manager in self._content_managers.items():
122+
self._initialize_content_manager(drive_name, content_manager["provider"], content_manager["location"])
123+
124+
def _initialize_content_manager(self, drive_name, provider, region=None):
125+
try:
126+
if provider == 's3':
127+
if self._config.session_token is None:
128+
configuration = {
129+
"aws_access_key_id": self._config.access_key_id,
130+
"aws_secret_access_key": self._config.secret_access_key,
131+
"aws_region": region,
132+
}
133+
else:
134+
configuration = {
135+
"aws_access_key_id": self._config.access_key_id,
136+
"aws_secret_access_key": self._config.secret_access_key,
137+
"aws_session_token": self._config.session_token,
138+
"aws_region": region,
139+
}
140+
store = obs.store.S3Store.from_url("s3://" + drive_name + "/", config = configuration)
141+
elif provider == 'gcs':
142+
store = obs.store.GCSStore.from_url("gs://" + drive_name + "/", config = {}) # add gcs config
143+
elif provider == 'http':
144+
store = obs.store.HTTPStore.from_url(drive_name, client_options = {}) # add http client config
145+
146+
self._content_managers[drive_name] = {
147+
"store": store,
148+
"location": region,
149+
"provider": provider,
150+
}
151+
except Exception as e:
152+
raise tornado.web.HTTPError(
153+
status_code=httpx.codes.BAD_REQUEST,
154+
reason=f"The following error occured when initializing the content manager: {e}",
155+
)
156+
119157
def set_listing_limit(self, new_limit):
120158
"""Set new limit for listing.
121159
@@ -183,42 +221,10 @@ async def mount_drive(self, drive_name, provider):
183221
Args:
184222
drive_name: name of drive to mount
185223
"""
186-
try:
187-
# check if content manager doesn't already exist
188-
if drive_name not in self._content_managers or self._content_managers[drive_name] is None:
189-
if provider == 's3':
190-
# get region of drive
191-
region = await self._get_drive_location(drive_name)
192-
if self._config.session_token is None:
193-
configuration = {
194-
"aws_access_key_id": self._config.access_key_id,
195-
"aws_secret_access_key": self._config.secret_access_key,
196-
"aws_region": region
197-
}
198-
else:
199-
configuration = {
200-
"aws_access_key_id": self._config.access_key_id,
201-
"aws_secret_access_key": self._config.secret_access_key,
202-
"aws_session_token": self._config.session_token,
203-
"aws_region": region
204-
}
205-
store = obs.store.S3Store.from_url("s3://" + drive_name + "/", config = configuration)
206-
elif provider == 'gcs':
207-
store = obs.store.GCSStore.from_url("gs://" + drive_name + "/", config = {}) # add gcs config
208-
elif provider == 'http':
209-
store = obs.store.HTTPStore.from_url(drive_name, client_options = {}) # add http client config
210-
211-
self._content_managers[drive_name] = {
212-
"store": store,
213-
"location": region
214-
}
215-
216-
else:
217-
raise tornado.web.HTTPError(
218-
status_code= httpx.codes.CONFLICT,
219-
reason= "Drive already mounted."
220-
)
221-
224+
try:
225+
if provider == 's3':
226+
region = await self._get_drive_location(drive_name)
227+
self._initialize_content_manager(drive_name, provider, region)
222228
except Exception as e:
223229
raise tornado.web.HTTPError(
224230
status_code= httpx.codes.BAD_REQUEST,

src/contents.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,11 @@ export class Drive implements Contents.IDrive {
230230
// when accessed the first time, mount drive
231231
if (currentDrive.mounted === false) {
232232
try {
233-
await mountDrive(localPath, {
233+
const driveName = currentDrive.name;
234+
await mountDrive(driveName, {
234235
provider: currentDrive.provider
235236
});
236-
this._drivesList.filter(x => x.name === localPath)[0].mounted = true;
237+
this._drivesList.filter(x => x.name === driveName)[0].mounted = true;
237238
} catch (e) {
238239
// it will give an error if drive is already mounted
239240
}

0 commit comments

Comments
 (0)