Skip to content

Commit

Permalink
feat: add polybox storage
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-code committed Nov 12, 2024
1 parent 1609c03 commit bd555db
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions components/renku_data_services/storage/rclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,105 @@ def __patch_schema_remove_oauth_propeties(spec: list[dict[str, Any]]) -> None:
options.append(option)
storage["Options"] = options

@staticmethod
def __patch_schema_add_polybox_storage(self, spec: list[dict[str, Any]]) -> None:
"""Add PolyBox storage configuration as a copy of WebDAV with modified options."""
# Find the WebDAV storage schema
webdav_storage = next((s for s in spec if s["Prefix"] == "webdav"), None)

if not webdav_storage:
raise errors.ValidationError("WebDAV storage not found in schema.")

# Create a copy of WebDAV storage and modify it to be PolyBox
polybox_storage = webdav_storage.copy()
polybox_storage["Prefix"] = "polybox"
polybox_storage["Name"] = "PolyBox"
polybox_storage["Description"] = "Polybox"

# Add new options: access_level and publicLink
polybox_storage["Options"].append({
"Name": "access_level",
"Help": "Choose the mode to access the data source.",
"Provider": "",
"Default": "",
"Examples": [
{"Value": "Private", "Help": "Use Private to connect a folder that only you use", "Provider": ""},
{"Value": "Public", "Help": "To connect a folder you share with others, both privately & publicly shared folders.", "Provider": ""}
],
"ShortOpt": "",
"Hide": 0,
"Required": True,
"IsPassword": False,
"NoPrefix": False,
"Advanced": False,
"Exclusive": False,
"Sensitive": False,
"DefaultStr": "",
"ValueStr": "",
"Type": "string"
})
polybox_storage["Options"].append({
"Name": "publicLink",
"Help": "shared folder link.\n\nE.g. https://polybox.ethz.ch/index.php/s/8NffJ3rFyHaVjgR",
"AccessLevel": "Public",
"Default": "",
"Value": None,
"Examples": None,
"ShortOpt": "",
"Hide": 0,
"Required": True,
"IsPassword": False,
"NoPrefix": False,
"Advanced": False,
"Exclusive": False,
"Sensitive": False,
"DefaultStr": "",
"ValueStr": "",
"Type": "string"
})

# Modify existing options for PolyBox
# Modify URL option
url_option = next(o for o in polybox_storage["Options"] if o["Name"] == "url")
url_option["AccessLevel"] = "Private"
url_option["Value"] = "https://polybox.ethz.ch/remote.php/webdav/"

# Modify user option
user_option = next(o for o in polybox_storage["Options"] if o["Name"] == "user")
user_option["Help"] = "#id, where #id is the identifier of your data (e.g. #id = i974KegIjhJJxkK for the last part of the URL of your data)"
user_option["AccessLevel"] = "Private"

# Modify pass option
pass_option = next(o for o in polybox_storage["Options"] if o["Name"] == "pass")
pass_option["Examples"] = [
{
"Value": "",
"Help": "We strongly encourage you to generate a token for accessing your private OwnCloud/Nextcloud WebDAV shares to avoid sharing your account password. To create the token, in your cloud storage application (PolyBox), go to “Settings: Security” and generate a new “Application pass-code” at the bottom of the page.",
"AccessLevel": "Private",
"Provider": "",
"FriendlyName": "Token (or password)"
},
{
"Value": "",
"Help": "If you set a password for the shared folder, enter that in the password field. Otherwise, leave it blank",
"AccessLevel": "Public",
"Provider": "",
"FriendlyName": "Password"
}
]

# Modify bearer_token and bearer_token_command options
for option_name in ["bearer_token", "bearer_token_command"]:
option = next(o for o in polybox_storage["Options"] if o["Name"] == option_name)
option["AccessLevel"] = "Private"

# Remove unwanted options
for option_name in ["vendor", "nextcloud_chunk_size"]:
polybox_storage["Options"] = [o for o in polybox_storage["Options"] if o["Name"] != option_name]

# Append PolyBox storage configuration to the schema
spec.append(polybox_storage)

def apply_patches(self, spec: list[dict[str, Any]]) -> None:
"""Apply patches to RClone schema."""
patches = [
Expand Down Expand Up @@ -271,6 +370,7 @@ class RCloneOption(BaseModel):
name: str = Field(alias="Name")
help: str = Field(alias="Help")
provider: str = Field(alias="Provider")
access_level: str = Field(alias="AccessLevel")
default: str | int | bool | list[str] | RCloneTriState | None = Field(alias="Default")
value: str | int | bool | RCloneTriState | None = Field(alias="Value")
examples: list[RCloneExample] | None = Field(default=None, alias="Examples")
Expand Down

0 comments on commit bd555db

Please sign in to comment.