Skip to content

Commit 10caa71

Browse files
committed
Inherit URL and credentials name config in subdatasets
This is criticial for authed-access. Notes are inside how this could be done better. But for now, speed is more important.
1 parent 2147bbc commit 10caa71

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

datalad_xnat/update.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def __call__(project=None,
9797
jobs='auto',
9898
dataset=None):
9999

100+
100101
ds = require_dataset(
101102
dataset, check_installed=True, purpose='update')
102103

@@ -161,6 +162,7 @@ def __call__(project=None,
161162
# go with a single big one
162163
subjects = [None]
163164
from datalad_xnat.parser import parse_xnat
165+
from unittest.mock import patch
164166
for sub in subjects:
165167
try:
166168
# all this tempfile madness is only needed because windows
@@ -189,16 +191,31 @@ def __call__(project=None,
189191
# corresponds to the header field 'filename' in the csv table
190192
filename = '{filename}'
191193
filenameformat = f"{pathfmt}{filename}"
192-
ds.addurls(
193-
str(addurls_table_fname), '{url}', filenameformat,
194-
ifexists=ifexists,
195-
fast=True if reckless == 'fast'
196-
else False,
197-
save=True,
198-
jobs=jobs,
199-
cfg_proc=None if platform.credential_name == 'anonymous'
200-
else 'xnat_dataset',
201-
result_renderer='default')
194+
# shoehorn essential info into the ENV to make it
195+
# accessible to the config procedure
196+
# TODO maybe alter the config procedure to pull this info
197+
# from a superdataset, if it finds the dataset at hand
198+
# unconfigured.
199+
env_prefix = f'DATALAD_XNAT_{xnat_cfg_name.upper()}'
200+
env = {
201+
'DATALAD_XNAT_DEFAULT__NAME': xnat_cfg_name,
202+
f'{env_prefix}_URL': platform.url,
203+
}
204+
if platform.credential_name != 'anonymous':
205+
env[f'{env_prefix}_CREDENTIAL__NAME'] = \
206+
platform.credential_name
207+
with patch.dict('os.environ', env):
208+
ds.addurls(
209+
str(addurls_table_fname), '{url}', filenameformat,
210+
ifexists=ifexists,
211+
fast=True if reckless == 'fast'
212+
else False,
213+
save=True,
214+
jobs=jobs,
215+
cfg_proc=None
216+
if platform.credential_name == 'anonymous'
217+
else 'xnat_dataset',
218+
result_renderer='default')
202219
finally:
203220
if addurls_table_fname.exists():
204221
addurls_table_fname.unlink()

0 commit comments

Comments
 (0)