-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EBR-79: extend files from ebrains_drive for bucket implementation
- Loading branch information
1 parent
cecb358
commit ad02218
Showing
6 changed files
with
109 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# "TheVirtualBrain - Widgets" package | ||
# | ||
# (c) 2022-2024, TVB Widgets Team | ||
# | ||
|
||
from ebrains_drive import BucketApiClient | ||
from tvbwidgets.core.bucket.buckets import ExtendedBuckets | ||
|
||
|
||
class ExtendedBucketApiClient(BucketApiClient): | ||
|
||
def __init__(self, username=None, password=None, token=None, env="") -> None: | ||
super().__init__(username, password, token, env) | ||
self.buckets = ExtendedBuckets(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# "TheVirtualBrain - Widgets" package | ||
# | ||
# (c) 2022-2024, TVB Widgets Team | ||
# | ||
|
||
from dataclasses import dataclass | ||
from typing import List | ||
from ebrains_drive.buckets import Buckets | ||
from tvbwidgets.core.exceptions import BucketDTOError | ||
from tvbwidgets.core.logger.builder import get_logger | ||
|
||
LOGGER = get_logger(__name__) | ||
|
||
|
||
@dataclass | ||
class BucketDTO: | ||
name: str | ||
role: str | ||
is_public: bool | ||
|
||
|
||
class ExtendedBuckets(Buckets): | ||
BUCKETS_ENDPOINT = '/v1/buckets' | ||
|
||
def __init__(self, client): | ||
super().__init__(client) | ||
self._available_buckets: List[BucketDTO] = [] | ||
|
||
def list_buckets(self): | ||
# type: () -> List[BucketDTO] | ||
""" | ||
Queries the buckets endpoint for the available buckets for current user | ||
""" | ||
try: | ||
resp = self.client.get(self.BUCKETS_ENDPOINT) | ||
json_resp = resp.json() | ||
updated_available_buckets = [] | ||
for obj in json_resp: | ||
updated_available_buckets.append(BucketDTO(**obj)) | ||
self._available_buckets = updated_available_buckets | ||
return self._available_buckets | ||
except KeyError as e: | ||
LOGGER.error(f'Received unexpected Bucket structure! {str(e)}') | ||
raise BucketDTOError('Unexpected response structure from server!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters