Skip to content

Commit

Permalink
cleaned up wb settings creation
Browse files Browse the repository at this point in the history
  • Loading branch information
opaduchak committed Nov 5, 2024
1 parent a2c8543 commit a90ffed
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 27 deletions.
4 changes: 2 additions & 2 deletions addon_imps/storage/box_dot_com.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +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, host: str) -> dict:
async def build_wb_config(self) -> dict:
return {
"folder": root_folder_id.split(":")[1],
"folder": self.config.connected_root_id.split(":")[1],
}

async def get_item_info(self, item_id: str) -> storage.ItemResult:
Expand Down
8 changes: 5 additions & 3 deletions addon_imps/storage/dataverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +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 def build_wb_config(
self,
) -> dict:
match = DATASET_REGEX.match(self.config.connected_root_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,
"host": urlparse(self.config.external_api_url).hostname,
}

async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResult:
Expand Down
4 changes: 2 additions & 2 deletions addon_imps/storage/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ 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, _: str) -> dict:
async def build_wb_config(self) -> dict:
return {
"folder": root_folder_id,
"folder": self.config.connected_root_id,
}

async def get_item_info(self, item_id: str) -> storage.ItemResult:
Expand Down
4 changes: 2 additions & 2 deletions addon_imps/storage/figshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ 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, _: str) -> dict:
segments = root_folder_id.split("/")
async def build_wb_config(self) -> dict:
segments = self.config.connected_root_id.split("/")
return {"container_type": segments[0], "container_id": segments[1]}

async def get_item_info(self, item_id: str) -> storage.ItemResult:
Expand Down
4 changes: 2 additions & 2 deletions addon_imps/storage/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ 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, _: str) -> dict:
owner, repo, _ = self._parse_github_item_id(root_folder_id)
async def build_wb_config(self) -> dict:
owner, repo, _ = self._parse_github_item_id(self.config.connected_root_id)
return {
"owner": owner,
"repo": repo,
Expand Down
6 changes: 3 additions & 3 deletions addon_imps/storage/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ 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)
async def build_wb_config(self) -> dict:
item_id = ItemId.parse(self.config.connected_root_id)
owner, repo_name = unquote_plus(item_id.repo_id).split("/")
repo = await self._get_repository(item_id.repo_id)
url = urlparse(host)
url = urlparse(self.config.external_api_url)
return {
"repo": repo_name,
"repo_id": str(repo.id),
Expand Down
4 changes: 2 additions & 2 deletions addon_imps/storage/google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ 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, _: str) -> dict:
return {"folder": {"id": root_folder_id}}
async def build_wb_config(self) -> dict:
return {"folder": {"id": self.config.connected_root_id}}

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

async def build_wb_config(self, root_folder_id: str, _: str) -> dict:
async def build_wb_config(self) -> dict:
async with self.network.GET("me/drive") as _response:
json = await _response.json_content()
return {
"folder": root_folder_id,
"folder": self.config.connected_root_id,
"drive_id": json.get("id"),
}

Expand Down
6 changes: 3 additions & 3 deletions addon_imps/storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ 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, _: str) -> dict:
async def build_wb_config(self) -> dict:
return {
"bucket": root_folder_id.split(":/")[0],
"id": root_folder_id,
"bucket": self.config.connected_root_id.split(":/")[0],
"id": self.config.connected_root_id,
"encrypt_uploads": True, # TODO: somehow include this into settings
}

Expand Down
6 changes: 1 addition & 5 deletions addon_service/common/waterbutler_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,4 @@ def _config_for_waterbutler(self, configured_storage_addon: ConfiguredStorageAdd
configured_storage_addon.base_account,
configured_storage_addon.config,
)
imp_config = async_to_sync(imp.build_wb_config)(
configured_storage_addon.root_folder,
configured_storage_addon.base_account.api_base_url,
)
return imp_config
return async_to_sync(imp.build_wb_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, host: str) -> dict:
async def build_wb_config(self) -> dict:
return {}


Expand Down

0 comments on commit a90ffed

Please sign in to comment.