Skip to content

Commit c4db01c

Browse files
authored
Datastore client: use datastore token correctly for download (#562)
* Update context.py * use token for download * Update context.py * refactoring * add changelog entry * Merge refs/heads/master into datastore_client_use_datastore_token * fix snapshots
1 parent b4e2c32 commit c4db01c

File tree

6 files changed

+6597
-6566
lines changed

6 files changed

+6597
-6566
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ For upgrade instructions, please check the respective *Breaking Changes* section
3636
### Changed
3737

3838
### Fixed
39+
- Fixed the dataset download of private datasets which need a token. [#562](https://github.com/scalableminds/webknossos-libs/pull/562)
3940

4041

4142
## [0.8.31](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.8.31) - 2022-01-07

webknossos/tests/cassettes/test_examples/test_learned_segmenter.yaml

Lines changed: 6580 additions & 6542 deletions
Large diffs are not rendered by default.

webknossos/tests/docker-compose.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ services:
77
ports:
88
- "9000:9000"
99
depends_on:
10-
postgres:
11-
condition: service_healthy
12-
fossildb:
13-
condition: service_healthy
14-
redis:
15-
condition: service_healthy
10+
- postgres
11+
- fossildb
12+
- redis
1613
command:
1714
- -Dconfig.file=conf/application.conf
1815
- -Djava.net.preferIPv4Stack=true

webknossos/webknossos/client/_download_dataset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def download_dataset(
4343
datastore_client = _get_context().get_generated_datastore_client(
4444
parsed.data_store.url
4545
)
46+
optional_datastore_token = _get_context().datastore_token
4647

4748
actual_path = Path(dataset_name) if path is None else Path(path)
4849
if actual_path.exists():
@@ -98,6 +99,7 @@ def download_dataset(
9899
data_layer_name=layer_name,
99100
resolution=mag.max_dim_log2,
100101
client=datastore_client,
102+
token=optional_datastore_token,
101103
x=aligned_chunk_in_mag.topleft.x,
102104
y=aligned_chunk_in_mag.topleft.y,
103105
z=aligned_chunk_in_mag.topleft.z,

webknossos/webknossos/client/_upload_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def upload_dataset(
8585
# replicates https://github.com/scalableminds/webknossos/blob/master/frontend/javascripts/admin/dataset/dataset_upload_view.js
8686
time_str = strftime("%Y-%m-%dT%H-%M-%S", gmtime())
8787
upload_id = f"{time_str}__{uuid4()}"
88-
datastore_token = context.datastore_token
88+
datastore_token = context.datastore_required_token
8989
datastore_url = _cached_get_upload_datastore(context)
9090
datastore_client = _get_context().get_generated_datastore_client(datastore_url)
9191
simultaneous_uploads = jobs if jobs is not None else DEFAULT_SIMULTANEOUS_UPLOADS

webknossos/webknossos/client/context.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,14 @@ def organization(self) -> str:
137137
return _cached_get_org(self)
138138

139139
@property
140-
def datastore_token(self) -> str:
140+
def datastore_token(self) -> Optional[str]:
141+
if self.token is None:
142+
return None
143+
else:
144+
return _cached_get_datastore_token(self)
145+
146+
@property
147+
def datastore_required_token(self) -> str:
141148
return _cached_get_datastore_token(self)
142149

143150
@property
@@ -148,22 +155,8 @@ def generated_client(self) -> GeneratedClient:
148155
def generated_auth_client(self) -> GeneratedClient:
149156
return _cached__get_generated_client(self.url, self.required_token)
150157

151-
def get_generated_datastore_client(
152-
self, datastore_url: str, enforce_auth: bool = False
153-
) -> GeneratedClient:
154-
if enforce_auth:
155-
token: Optional[str] = self.required_token
156-
else:
157-
token = self.token
158-
159-
if token is None:
160-
return GeneratedClient(base_url=datastore_url, timeout=120)
161-
else:
162-
return GeneratedClient(
163-
base_url=datastore_url,
164-
headers={"X-Auth-Token": token},
165-
timeout=120,
166-
)
158+
def get_generated_datastore_client(self, datastore_url: str) -> GeneratedClient:
159+
return GeneratedClient(base_url=datastore_url, timeout=120)
167160

168161

169162
_webknossos_context_var: ContextVar[_WebknossosContext] = ContextVar(

0 commit comments

Comments
 (0)