Skip to content

Commit bce8bcf

Browse files
committed
feat: convert openBIS cloud storage configurations into valid rclone configurations before starting a session
1 parent 5c9b12a commit bce8bcf

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

components/renku_data_services/notebooks/api/schemas/cloud_storage.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,40 +219,46 @@ def get_manifest_patch(
219219
return patches
220220

221221
def config_string(self, name: str) -> str:
222-
"""Convert configuration oblect to string representation.
222+
"""Convert configuration object to string representation.
223223
224224
Needed to create RClone compatible INI files.
225225
"""
226226
if not self.configuration:
227227
raise ValidationError("Missing configuration for cloud storage")
228-
229-
# Transform configuration for polybox or switchDrive
228+
# TODO Use RCloneValidator.get_real_configuration(...) instead.
229+
real_config = dict(self.configuration)
230+
# Transform configuration for polybox, switchDrive or openBIS
230231
storage_type = self.configuration.get("type", "")
231232
access = self.configuration.get("provider", "")
232233

233234
if storage_type == "polybox" or storage_type == "switchDrive":
234-
self.configuration["type"] = "webdav"
235-
self.configuration["provider"] = ""
235+
real_config["type"] = "webdav"
236+
real_config["provider"] = ""
237+
elif storage_type == "s3" and access == "Switch":
238+
# Switch is a fake provider we add for users, we need to replace it since rclone itself
239+
# doesn't know it
240+
real_config["provider"] = "Other"
241+
elif storage_type == "openbis":
242+
real_config["type"] = "sftp"
243+
real_config["port"] = "2222"
244+
real_config["user"] = "?"
245+
real_config["pass"] = real_config.pop("session_token")
236246

237247
if access == "shared" and storage_type == "polybox":
238-
self.configuration["url"] = "https://polybox.ethz.ch/public.php/webdav/"
248+
real_config["url"] = "https://polybox.ethz.ch/public.php/webdav/"
239249
elif access == "shared" and storage_type == "switchDrive":
240-
self.configuration["url"] = "https://drive.switch.ch/public.php/webdav/"
250+
real_config["url"] = "https://drive.switch.ch/public.php/webdav/"
241251
elif access == "personal" and storage_type == "polybox":
242-
self.configuration["url"] = "https://polybox.ethz.ch/remote.php/webdav/"
252+
real_config["url"] = "https://polybox.ethz.ch/remote.php/webdav/"
243253
elif access == "personal" and storage_type == "switchDrive":
244-
self.configuration["url"] = "https://drive.switch.ch/remote.php/webdav/"
254+
real_config["url"] = "https://drive.switch.ch/remote.php/webdav/"
245255

246256
# Extract the user from the public link
247257
if access == "shared" and storage_type in {"polybox", "switchDrive"}:
248258
public_link = self.configuration.get("public_link", "")
249259
user_identifier = public_link.split("/")[-1]
250-
self.configuration["user"] = user_identifier
260+
real_config["user"] = user_identifier
251261

252-
if self.configuration["type"] == "s3" and self.configuration.get("provider", None) == "Switch":
253-
# Switch is a fake provider we add for users, we need to replace it since rclone itself
254-
# doesn't know it
255-
self.configuration["provider"] = "Other"
256262
parser = ConfigParser()
257263
parser.add_section(name)
258264

@@ -261,7 +267,7 @@ def _stringify(value: Any) -> str:
261267
return "true" if value else "false"
262268
return str(value)
263269

264-
for k, v in self.configuration.items():
270+
for k, v in real_config.items():
265271
parser.set(name, k, _stringify(v))
266272
stringio = StringIO()
267273
parser.write(stringio)

components/renku_data_services/storage/rclone.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,15 @@ def validate_sensitive_data(
361361
continue
362362
raise errors.ValidationError(message=f"The '{key}' property is not marked as sensitive.")
363363

364-
def get_real_config(self, configuration: Union["RCloneConfig", dict[str, Any]]) -> dict[str, Any]:
364+
def get_real_configuration(self, configuration: Union["RCloneConfig", dict[str, Any]]) -> dict[str, Any]:
365365
"""Converts a Renku rclone configuration to a real rclone config."""
366366
real_config = dict(configuration)
367-
if configuration["type"] == "openbis":
367+
368+
if real_config["type"] == "s3" and real_config.get("provider") == "Switch":
369+
# Switch is a fake provider we add for users, we need to replace it since rclone itself
370+
# doesn't know it
371+
real_config["provider"] = "Other"
372+
elif configuration["type"] == "openbis":
368373
real_config["type"] = "sftp"
369374
real_config["port"] = "2222"
370375
real_config["user"] = "?"
@@ -381,7 +386,7 @@ async def test_connection(
381386
return ConnectionResult(False, str(e))
382387

383388
# Obscure configuration and transform if needed
384-
obscured_config = await self.obscure_config(self.get_real_config(configuration))
389+
obscured_config = await self.obscure_config(self.get_real_configuration(configuration))
385390
transformed_config = self.transform_polybox_switchdriver_config(obscured_config)
386391

387392
with tempfile.NamedTemporaryFile(mode="w+", delete=False, encoding="utf-8") as f:

0 commit comments

Comments
 (0)