Skip to content

Commit 67dd950

Browse files
committed
feat: convert openBIS cloud storage configurations into valid rclone configurations before starting a session
1 parent 329ac12 commit 67dd950

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,24 @@ def get_manifest_patch(
210210
return patches
211211

212212
def config_string(self, name: str) -> str:
213-
"""Convert configuration oblect to string representation.
213+
"""Convert configuration object to string representation.
214214
215215
Needed to create RClone compatible INI files.
216216
"""
217217
if not self.configuration:
218218
raise ValidationError("Missing configuration for cloud storage")
219-
if self.configuration["type"] == "s3" and self.configuration.get("provider", None) == "Switch":
219+
# TODO Use RCloneValidator.get_real_configuration(...) instead.
220+
real_config = dict(self.configuration)
221+
if real_config["type"] == "s3" and real_config.get("provider") == "Switch":
220222
# Switch is a fake provider we add for users, we need to replace it since rclone itself
221223
# doesn't know it
222-
self.configuration["provider"] = "Other"
224+
real_config["provider"] = "Other"
225+
elif real_config["type"] == "openbis":
226+
real_config["type"] = "sftp"
227+
real_config["port"] = "2222"
228+
real_config["user"] = "?"
229+
real_config["pass"] = real_config.pop("session_token")
230+
223231
parser = ConfigParser()
224232
parser.add_section(name)
225233

@@ -228,7 +236,7 @@ def _stringify(value: Any) -> str:
228236
return "true" if value else "false"
229237
return str(value)
230238

231-
for k, v in self.configuration.items():
239+
for k, v in real_config.items():
232240
parser.set(name, k, _stringify(v))
233241
stringio = StringIO()
234242
parser.write(stringio)

components/renku_data_services/storage/rclone.py

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

249-
def get_real_config(self, configuration: Union["RCloneConfig", dict[str, Any]]) -> dict[str, Any]:
249+
def get_real_configuration(self, configuration: Union["RCloneConfig", dict[str, Any]]) -> dict[str, Any]:
250250
"""Converts a Renku rclone configuration to a real rclone config."""
251251
real_config = dict(configuration)
252-
if configuration["type"] == "openbis":
252+
253+
if real_config["type"] == "s3" and real_config.get("provider") == "Switch":
254+
# Switch is a fake provider we add for users, we need to replace it since rclone itself
255+
# doesn't know it
256+
real_config["provider"] = "Other"
257+
elif configuration["type"] == "openbis":
253258
real_config["type"] = "sftp"
254259
real_config["port"] = "2222"
255260
real_config["user"] = "?"
@@ -265,7 +270,7 @@ async def test_connection(
265270
except errors.ValidationError as e:
266271
return ConnectionResult(False, str(e))
267272

268-
obscured_rclone_config = await self.obscure_config(self.get_real_config(configuration))
273+
obscured_rclone_config = await self.obscure_config(self.get_real_configuration(configuration))
269274

270275
with tempfile.NamedTemporaryFile(mode="w+", delete=False, encoding="utf-8") as f:
271276
obscured_rclone_config_string = "\n".join(f"{k}={v}" for k, v in obscured_rclone_config.items())

0 commit comments

Comments
 (0)