Skip to content

Commit

Permalink
feat: convert openBIS cloud storage configurations into valid rclone …
Browse files Browse the repository at this point in the history
…configurations before starting a session
  • Loading branch information
olloz26 committed Dec 5, 2024
1 parent 116fd28 commit e2aa851
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,40 +210,46 @@ def get_manifest_patch(
return patches

def config_string(self, name: str) -> str:
"""Convert configuration oblect to string representation.
"""Convert configuration object to string representation.
Needed to create RClone compatible INI files.
"""
if not self.configuration:
raise ValidationError("Missing configuration for cloud storage")

# Transform configuration for polybox or switchDrive
# TODO Use RCloneValidator.get_real_configuration(...) instead.
real_config = dict(self.configuration)
# Transform configuration for polybox, switchDrive or openBIS
storage_type = self.configuration.get("type", "")
access = self.configuration.get("provider", "")

if storage_type == "polybox" or storage_type == "switchDrive":
self.configuration["type"] = "webdav"
self.configuration["provider"] = ""
real_config["type"] = "webdav"
real_config["provider"] = ""
elif storage_type == "s3" and access == "Switch":
# Switch is a fake provider we add for users, we need to replace it since rclone itself
# doesn't know it
real_config["provider"] = "Other"
elif storage_type == "openbis":
real_config["type"] = "sftp"
real_config["port"] = "2222"
real_config["user"] = "?"
real_config["pass"] = real_config.pop("session_token")

if access == "shared" and storage_type == "polybox":
self.configuration["url"] = "https://polybox.ethz.ch/public.php/webdav/"
real_config["url"] = "https://polybox.ethz.ch/public.php/webdav/"
elif access == "shared" and storage_type == "switchDrive":
self.configuration["url"] = "https://drive.switch.ch/public.php/webdav/"
real_config["url"] = "https://drive.switch.ch/public.php/webdav/"
elif access == "personal" and storage_type == "polybox":
self.configuration["url"] = "https://polybox.ethz.ch/remote.php/webdav/"
real_config["url"] = "https://polybox.ethz.ch/remote.php/webdav/"
elif access == "personal" and storage_type == "switchDrive":
self.configuration["url"] = "https://drive.switch.ch/remote.php/webdav/"
real_config["url"] = "https://drive.switch.ch/remote.php/webdav/"

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

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

Expand All @@ -252,7 +258,7 @@ def _stringify(value: Any) -> str:
return "true" if value else "false"
return str(value)

for k, v in self.configuration.items():
for k, v in real_config.items():
parser.set(name, k, _stringify(v))
stringio = StringIO()
parser.write(stringio)
Expand Down
11 changes: 8 additions & 3 deletions components/renku_data_services/storage/rclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,15 @@ def validate_sensitive_data(
continue
raise errors.ValidationError(message=f"The '{key}' property is not marked as sensitive.")

def get_real_config(self, configuration: Union["RCloneConfig", dict[str, Any]]) -> dict[str, Any]:
def get_real_configuration(self, configuration: Union["RCloneConfig", dict[str, Any]]) -> dict[str, Any]:
"""Converts a Renku rclone configuration to a real rclone config."""
real_config = dict(configuration)
if configuration["type"] == "openbis":

if real_config["type"] == "s3" and real_config.get("provider") == "Switch":
# Switch is a fake provider we add for users, we need to replace it since rclone itself
# doesn't know it
real_config["provider"] = "Other"
elif configuration["type"] == "openbis":
real_config["type"] = "sftp"
real_config["port"] = "2222"
real_config["user"] = "?"
Expand All @@ -381,7 +386,7 @@ async def test_connection(
return ConnectionResult(False, str(e))

# Obscure configuration and transform if needed
obscured_config = await self.obscure_config(self.get_real_config(configuration))
obscured_config = await self.obscure_config(self.get_real_configuration(configuration))
transformed_config = self.transform_polybox_switchdriver_config(obscured_config)

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

0 comments on commit e2aa851

Please sign in to comment.