Skip to content

Commit 5152361

Browse files
authored
List files would return everything if projects were empyt (#934)
1 parent dbb949e commit 5152361

File tree

7 files changed

+33
-27
lines changed

7 files changed

+33
-27
lines changed

services/storage/src/simcore_service_storage/data/docker-dev-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main:
33
host: 0.0.0.0
44
log_level: INFO
55
port: 8080
6-
testing: True
6+
testing: False
77
max_workers: 8
88
test_datcore:
99
token_key: ${BF_API_KEY}

services/storage/src/simcore_service_storage/data/docker-prod-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main:
33
host: 0.0.0.0
44
log_level: INFO
55
port: 8080
6-
testing: True
6+
testing: False
77
test_datcore:
88
token_key: ${BF_API_KEY}
99
token_secret: ${BF_API_SECRET}

services/storage/src/simcore_service_storage/data/host-dev-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ main:
44
host: 127.0.0.1
55
log_level: INFO
66
port: 8080
7-
testing: true
7+
testing: False
88
test_datcore:
99
token_key: ${BF_API_KEY}
1010
token_secret: ${BF_API_SECRET}

services/storage/src/simcore_service_storage/dsm.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
async def _setup_dsm(app: web.Application):
4545
cfg = app[APP_CONFIG_KEY]
46-
main_cfg = cfg["main"]
4746

4847
main_cfg = cfg["main"]
4948

@@ -57,7 +56,8 @@ async def _setup_dsm(app: web.Application):
5756
s3_cfg = get_config_s3(app)
5857
bucket_name = s3_cfg["bucket_name"]
5958

60-
dsm = DataStorageManager(s3_client, engine, loop, pool, bucket_name)
59+
testing = main_cfg["testing"]
60+
dsm = DataStorageManager(s3_client, engine, loop, pool, bucket_name, not testing)
6161

6262
app[APP_DSM_KEY] = dsm
6363

@@ -112,6 +112,8 @@ class DataStorageManager:
112112
loop: object
113113
pool: ThreadPoolExecutor
114114
simcore_bucket_name: str
115+
has_project_db: bool
116+
115117
datcore_tokens: Dict[str, DatCoreApiToken]=attr.Factory(dict)
116118
# TODO: perhaps can be used a cache? add a lifetime?
117119

@@ -185,25 +187,29 @@ async def list_files(self, user_id: str, location: str, uuid_filter: str ="", re
185187
d = FileMetaData(**result_dict)
186188
data.append(d)
187189

188-
uuid_name_dict = {}
189-
# now parse the project to search for node/project names
190-
try:
191-
async with self.engine.acquire() as conn:
192-
joint_table = user_to_projects.join(projects)
193-
query = sa.select([projects]).select_from(joint_table)\
194-
.where(user_to_projects.c.user_id == user_id)
195-
196-
async for row in conn.execute(query):
197-
proj_data = {key:value for key,value in row.items()}
198-
199-
uuid_name_dict[proj_data["uuid"]] = proj_data["name"]
200-
wb = proj_data['workbench']
201-
for node in wb.keys():
202-
uuid_name_dict[node] = wb[node]['label']
203-
except DBAPIError as _err:
204-
logger.exception("Error querying database for project names")
190+
if self.has_project_db:
191+
uuid_name_dict = {}
192+
# now parse the project to search for node/project names
193+
try:
194+
async with self.engine.acquire() as conn:
195+
joint_table = user_to_projects.join(projects)
196+
query = sa.select([projects]).select_from(joint_table)\
197+
.where(user_to_projects.c.user_id == user_id)
198+
199+
async for row in conn.execute(query):
200+
proj_data = {key:value for key,value in row.items()}
201+
202+
uuid_name_dict[proj_data["uuid"]] = proj_data["name"]
203+
wb = proj_data['workbench']
204+
for node in wb.keys():
205+
uuid_name_dict[node] = wb[node]['label']
206+
except DBAPIError as _err:
207+
logger.exception("Error querying database for project names")
208+
209+
if not uuid_name_dict:
210+
# there seems to be no project whatsoever for user_id
211+
return []
205212

206-
if uuid_name_dict:
207213
# only keep files from non-deleted project --> This needs to be fixed
208214
clean_data = []
209215
for d in data:
@@ -228,16 +234,14 @@ async def list_files(self, user_id: str, location: str, uuid_filter: str ="", re
228234
clean_data.append(d)
229235

230236
data = clean_data
231-
for d in data:
232-
logger.info(d)
233237

234238
# same as above, make sure file is physically present on s3
235239
clean_data = []
236240
# MaG: This is inefficient: Do this automatically when file is modified
237241
_loop = asyncio.get_event_loop()
238242
session = aiobotocore.get_session(loop=_loop)
239243
async with session.create_client('s3', endpoint_url="http://"+self.s3_client.endpoint, aws_access_key_id=self.s3_client.access_key,
240-
aws_secret_access_key=self.s3_client.secret_key) as client:
244+
aws_secret_access_key=self.s3_client.secret_key) as client:
241245
responses = await asyncio.gather(*[client.list_objects_v2(Bucket=d.bucket_name, Prefix=_d) for _d in [__d.object_name for __d in data]])
242246
for d, resp in zip(data, responses):
243247
if 'Contents' in resp:

services/storage/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ async def datcore_testbucket(loop, mock_files_factory):
308308
def dsm_fixture(s3_client, postgres_engine, loop):
309309
pool = ThreadPoolExecutor(3)
310310
dsm_fixture = DataStorageManager(
311-
s3_client, postgres_engine, loop, pool, BUCKET_NAME)
311+
s3_client, postgres_engine, loop, pool, BUCKET_NAME, False)
312312

313313
api_token = os.environ.get("BF_API_KEY", "none")
314314
api_secret = os.environ.get("BF_API_SECRET", "none")

services/storage/tests/test_dsm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ def test_fmd_build():
355355
async def test_dsm_complete_db(dsm_fixture, dsm_mockup_complete_db):
356356
dsm = dsm_fixture
357357
_id = "21"
358+
dsm.has_project_db = True
358359
data = await dsm.list_files(user_id=_id, location=SIMCORE_S3_STR)
359360

360361
assert len(data) == 2

services/storage/tests/test_rest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def client(loop, aiohttp_unused_port, aiohttp_client, postgres_service, minio_se
3838
'port': aiohttp_unused_port(),
3939
'host': 'localhost',
4040
"max_workers" : 4,
41+
"testing" : True,
4142
"test_datcore" : { 'api_token' : api_token, 'api_secret' : api_secret}
4243
}
4344
rest_cfg = {

0 commit comments

Comments
 (0)