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 13, 2024
1 parent 1609c03 commit dfa1925
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
7 changes: 7 additions & 0 deletions components/renku_data_services/storage/api.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ components:
type: string
description: The cloud provider the option is for (See 'provider' RCloneOption in the schema for potential values)
example: AWS
access_level:
type: string
description: TBD
example: Public
public_link:
type: string
description: TBD
default:
oneOf:
- type: number
Expand Down
115 changes: 114 additions & 1 deletion components/renku_data_services/storage/rclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self) -> None:
provider_schema = RCloneProviderSchema.model_validate(provider_config)
self.providers[provider_schema.prefix] = provider_schema
except ValidationError:
logger.error("Couldn't load RClone config: %s", provider_config)
logger.error("🚀 Couldn't load RClone config: %s", provider_config)
raise

@staticmethod
Expand Down Expand Up @@ -156,6 +156,116 @@ 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(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(message="🦩 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": "",
"AccessLevel": None,
"PublicLink": None,
"Default": "",
"Value": None,
"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",
"Provider": "",
"AccessLevel": "Public",
"PublicLink": None,
"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"] = ""
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": "",
"AccessLevel": "Private",
"Provider": "",
},
{
"Value": "",
"Help": "",
"AccessLevel": "Public",
"Provider": "",
},
]

# 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 @@ -263,6 +373,7 @@ class RCloneExample(BaseModel):
value: str = Field(alias="Value")
help: str = Field(alias="Help")
provider: str = Field(alias="Provider")
access_level: str | None = Field(alias="AccessLevel", default=None)


class RCloneOption(BaseModel):
Expand All @@ -271,6 +382,8 @@ class RCloneOption(BaseModel):
name: str = Field(alias="Name")
help: str = Field(alias="Help")
provider: str = Field(alias="Provider")
access_level: str | None = Field(alias="AccessLevel", default=None)
public_link: str | None = Field(alias="PublicLink", default=None)
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 dfa1925

Please sign in to comment.