Skip to content

Commit 018d86e

Browse files
authored
Merge pull request #606 from dcs4cop/toniof-xxx-fix_for_s3_configs
Corrected retrieval of store params
2 parents 421c6b3 + 2788571 commit 018d86e

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

test/webapi/test_context.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,27 @@ def test_get_global_place_group(self):
197197
ctx.get_global_place_group("bibo", "http://localhost:9090")
198198
self.assertEqual('HTTP 404: Place group "bibo" not found', f"{cm.exception}")
199199

200+
def test_get_other_store_params_than_root(self):
201+
ctx = new_test_service_context()
202+
dataset_config = {'Identifier': 'two',
203+
'Title': 'Test 2',
204+
'FileSystem': 's3',
205+
'Anonymous': False,
206+
'Endpoint': 'https://s3.eu-central-1.amazonaws.com',
207+
'Path': 'xcube-examples/OLCI-SNS-RAW-CUBE-2.zarr',
208+
'Region': 'eu-central-1'}
209+
store_params = ctx._get_other_store_params_than_root(dataset_config)
210+
expected_dict = \
211+
{'storage_options':
212+
{'anon': False,
213+
'client_kwargs':
214+
{'endpoint_url': 'https://s3.eu-central-1.amazonaws.com',
215+
'region_name': 'eu-central-1'}
216+
}
217+
}
218+
self.assertIsNotNone(store_params)
219+
self.assertEqual(expected_dict, store_params)
220+
200221

201222
class NormalizePrefixTest(unittest.TestCase):
202223
def test_empty(self):

xcube/webapi/context.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def _maybe_assign_store_instance_ids(self):
308308
# Determine common prefixes of paths (and call them roots)
309309
prefixes = _get_common_prefixes(paths)
310310
if len(prefixes) < 1:
311-
roots = prefixes
311+
roots = ['']
312312
else:
313313
# perform further step to merge prefixes with same start
314314
prefixes = list(set(prefixes))
@@ -329,6 +329,8 @@ def _maybe_assign_store_instance_ids(self):
329329
while not root.endswith("/") and not root.endswith("\\") and \
330330
len(root) > 0:
331331
root = root[:-1]
332+
if root.endswith("/") or root.endswith("\\"):
333+
root = root[:-1]
332334
abs_root = root
333335
# For local file systems: Determine absolute root from base dir
334336
fs_protocol = FS_TYPE_TO_PROTOCOL.get(file_system, file_system)
@@ -352,28 +354,32 @@ def _maybe_assign_store_instance_ids(self):
352354
store_instance_id = f'{fs_protocol}_{counter}'
353355
data_store_pool.add_store_config(store_instance_id,
354356
data_store_config)
355-
356357
for config in config_list:
357358
if config['Path'].startswith(root):
358359
config['StoreInstanceId'] = store_instance_id
359-
config['Path'] = config['Path'][len(root):]
360+
new_path = config['Path'][len(root):]
361+
while new_path.startswith("/") or \
362+
new_path.startswith("\\"):
363+
new_path = new_path[1:]
364+
config['Path'] = new_path
360365

361366
def _get_other_store_params_than_root(self,
362367
dataset_config: DatasetConfigDict) \
363368
-> Dict:
364369
if FS_TYPE_TO_PROTOCOL.get(dataset_config.get('FileSystem',
365370
'file')) != 's3':
366371
return {}
367-
store_params = dict()
372+
storage_options=dict()
368373
if 'Anonymous' in dataset_config:
369-
store_params['anon'] = dataset_config['Anonymous']
374+
storage_options['anon'] = dataset_config['Anonymous']
370375
client_kwargs = dict(
371376
)
372377
if 'Endpoint' in dataset_config:
373378
client_kwargs['endpoint_url'] = dataset_config['Endpoint']
374379
if 'Region' in dataset_config:
375380
client_kwargs['region_name'] = dataset_config['Region']
376-
store_params['client_kwargs'] = client_kwargs
381+
storage_options['client_kwargs'] = client_kwargs
382+
store_params = dict(storage_options=storage_options)
377383
return store_params
378384

379385
def get_dataset_configs_from_stores(self) \

0 commit comments

Comments
 (0)