Skip to content

Commit

Permalink
fixed rest of already implemented providers
Browse files Browse the repository at this point in the history
  • Loading branch information
opaduchak committed Nov 5, 2024
1 parent 5bc93a7 commit a2c8543
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 13 deletions.
3 changes: 1 addition & 2 deletions addon_imps/storage/box_dot_com.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResu
total_count=1,
)

async def build_wb_config(self, root_folder_id: str, service_name: str) -> dict:
async def build_wb_config(self, root_folder_id: str, host: str) -> dict:
return {
"folder": root_folder_id.split(":")[1],
"service": service_name,
}

async def get_item_info(self, item_id: str) -> storage.ItemResult:
Expand Down
13 changes: 13 additions & 0 deletions addon_imps/storage/dataverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import re
from dataclasses import dataclass
from urllib.parse import urlparse

from addon_toolkit.interfaces import storage
from addon_toolkit.interfaces.storage import (
Expand All @@ -27,6 +28,18 @@ class DataverseStorageImp(storage.StorageAddonHttpRequestorImp):
async def get_external_account_id(self, _: dict[str, str]) -> str:
return ""

async def build_wb_config(self, root_folder_id: str, host: str) -> dict:
match = DATASET_REGEX.match(root_folder_id)
async with self.network.GET(f"datasets/{match['id']}") as response:
content = await response.json_content()
parsed = parse_dataset(content)
return {
"id": match["id"],
"name": parsed.item_name,
"doi": content["data"]["latestVersion"]["datasetPersistentId"],
"host": urlparse(host).hostname,
}

async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResult:
async with self.network.GET(
"mydata/retrieve",
Expand Down
2 changes: 1 addition & 1 deletion addon_imps/storage/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def get_external_account_id(self, _: dict[str, str]) -> str:
async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResult:
return await self.list_child_items(item_id="", page_cursor=page_cursor)

async def build_wb_config(self, root_folder_id: str, service_name: str) -> dict:
async def build_wb_config(self, root_folder_id: str, _: str) -> dict:
return {
"folder": root_folder_id,
}
Expand Down
2 changes: 1 addition & 1 deletion addon_imps/storage/figshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResu
next_sample_cursor=str(page_cursor + 1),
)

async def build_wb_config(self, root_folder_id: str, service_name: str) -> dict:
async def build_wb_config(self, root_folder_id: str, _: str) -> dict:
segments = root_folder_id.split("/")
return {"container_type": segments[0], "container_id": segments[1]}

Expand Down
2 changes: 1 addition & 1 deletion addon_imps/storage/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResu
items=items, total_count=len(items)
).with_cursor(self._create_offset_cursor(len(items), page_cursor))

async def build_wb_config(self, root_folder_id: str, service_name: str) -> dict:
async def build_wb_config(self, root_folder_id: str, _: str) -> dict:
owner, repo, _ = self._parse_github_item_id(root_folder_id)
return {
"owner": owner,
Expand Down
23 changes: 20 additions & 3 deletions addon_imps/storage/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import urllib
from dataclasses import dataclass
from http import HTTPStatus
from urllib.parse import quote_plus
from urllib.parse import (
quote_plus,
unquote_plus,
urlparse,
)

from addon_imps.storage.utils import ItemResultable
from addon_service.common.exceptions import ItemNotFound
Expand All @@ -29,6 +33,18 @@ async def get_external_account_id(self, _: dict[str, str]) -> str:
resp_json = await response.json_content()
return resp_json.get("user_id", "")

async def build_wb_config(self, root_folder_id: str, host: str) -> dict:
item_id = ItemId.parse(root_folder_id)
owner, repo_name = unquote_plus(item_id.repo_id).split("/")
repo = await self._get_repository(item_id.repo_id)
url = urlparse(host)
return {
"repo": repo_name,
"repo_id": str(repo.id),
"owner": owner,
"host": f"{url.scheme}://{url.hostname}",
}

async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResult:
query_params = self._page_cursor_or_query(
page_cursor,
Expand Down Expand Up @@ -74,12 +90,12 @@ async def get_item_info(self, item_id: str) -> storage.ItemResult:
if parsed_id.file_path:
return await self.get_file_or_folder(parsed_id)

return await self._get_repository(parsed_id.repo_id)
return (await self._get_repository(parsed_id.repo_id)).item_result

async def _get_repository(self, repo_id):
async with self.network.GET(f"projects/{repo_id}") as response:
content = await response.json_content()
return Repository.from_json(content).item_result
return Repository.from_json(content)

async def get_file_or_folder(self, parsed_id: ItemId):
async with self.network.GET(f"projects/{parsed_id.repo_id}") as response:
Expand Down Expand Up @@ -173,6 +189,7 @@ def parse_item(repo_id: str, raw_item: dict) -> ItemResult:
@dataclass(frozen=True, slots=True)
class Repository(ItemResultable):
path_with_namespace: str
id: int
name: str

@property
Expand Down
2 changes: 1 addition & 1 deletion addon_imps/storage/google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def get_external_account_id(self, _: dict[str, str]) -> str:
async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResult:
return ItemSampleResult(items=[await self.get_item_info("root")], total_count=1)

async def build_wb_config(self, root_folder_id: str, service_name: str) -> dict:
async def build_wb_config(self, root_folder_id: str, _: str) -> dict:
return {"folder": {"id": root_folder_id}}

async def get_item_info(self, item_id: str) -> storage.ItemResult:
Expand Down
2 changes: 1 addition & 1 deletion addon_imps/storage/onedrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResu
total_count=1,
)

async def build_wb_config(self, root_folder_id: str, service_name: str) -> dict:
async def build_wb_config(self, root_folder_id: str, _: str) -> dict:
async with self.network.GET("me/drive") as _response:
json = await _response.json_content()
return {
Expand Down
2 changes: 1 addition & 1 deletion addon_imps/storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_client(credentials: AccessKeySecretKeyCredentials):
"s3", aws_access_key_id=access_key, aws_secret_access_key=secret_key
)

async def build_wb_config(self, root_folder_id: str, service_name: str) -> dict:
async def build_wb_config(self, root_folder_id: str, _: str) -> dict:
return {
"bucket": root_folder_id.split(":/")[0],
"id": root_folder_id,
Expand Down
2 changes: 1 addition & 1 deletion addon_service/common/waterbutler_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ def _config_for_waterbutler(self, configured_storage_addon: ConfiguredStorageAdd
)
imp_config = async_to_sync(imp.build_wb_config)(
configured_storage_addon.root_folder,
configured_storage_addon.external_service.wb_key,
configured_storage_addon.base_account.api_base_url,
)
return imp_config
2 changes: 1 addition & 1 deletion addon_toolkit/interfaces/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class StorageAddonImp(AddonImp):

config: StorageConfig

async def build_wb_config(self, root_folder_id: str, service_name: str) -> dict:
async def build_wb_config(self, root_folder_id: str, host: str) -> dict:
return {}


Expand Down

0 comments on commit a2c8543

Please sign in to comment.