@@ -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 ,
0 commit comments