@@ -32,6 +32,14 @@ def test_mkvmod(mod):
3232 return dj .create_virtual_module (
3333 mod , dj .config .get ('database.prefix' , '' ) + 'test_ibl_{}' .format (mod ))
3434
35+ # set up the aws s3 bucket name depending on public/internal
36+ if os .environ .get ('API_MODE' ) in ['private' , None ]:
37+ BUCKET_LOCATION = 'ibl-dj-external'
38+ elif os .environ .get ('API_MODE' ) == 'public' :
39+ BUCKET_LOCATION = 'ibl-dj-external-public'
40+ else :
41+ raise Exception ('Invalid API_MODE, it should either be not defined / private / public, please check your environment variables.' )
42+
3543
3644subject = mkvmod ('subject' )
3745reference = mkvmod ('reference' )
@@ -54,15 +62,15 @@ def test_mkvmod(mod):
5462 endpoint = 's3.amazonaws.com' ,
5563 access_key = os .environ .get ('AWS_ACCESS_KEY_ID' ),
5664 secret_key = os .environ .get ('AWS_SECRET_ACCESS_KEY' ),
57- bucket = 'ibl-dj-external' ,
65+ bucket = BUCKET_LOCATION ,
5866 location = '/ephys'
5967 ),
6068 'plotting' : dict (
6169 protocol = 's3' ,
6270 endpoint = 's3.amazonaws.com' ,
6371 access_key = os .environ .get ('AWS_ACCESS_KEY_ID' ),
6472 secret_key = os .environ .get ('AWS_SECRET_ACCESS_KEY' ),
65- bucket = 'ibl-dj-external' ,
73+ bucket = BUCKET_LOCATION ,
6674 location = '/plotting'
6775 )
6876}
@@ -355,7 +363,7 @@ def post_process(ret):
355363 if parsed_item ['plotting_data_link' ] != '' and parsed_item ['plotting_data_link' ] != None : # if empty link or NULL, skip
356364 parsed_item ['plotting_data_link' ] = \
357365 s3_client .generate_presigned_url ('get_object' ,
358- Params = {'Bucket' : 'ibl-dj-external' , 'Key' : parsed_item ['plotting_data_link' ]},
366+ Params = {'Bucket' : BUCKET_LOCATION , 'Key' : parsed_item ['plotting_data_link' ]},
359367 ExpiresIn = 3 * 60 * 60 )
360368 parsed_items .append (parsed_item )
361369 return parsed_items
@@ -374,17 +382,17 @@ def post_process(ret):
374382 if parsed_item ['plotting_data_link' ] != '' : # if empty link, skip
375383 parsed_item ['plotting_data_link' ] = \
376384 s3_client .generate_presigned_url ('get_object' ,
377- Params = {'Bucket' : 'ibl-dj-external' , 'Key' : parsed_item ['plotting_data_link' ]},
385+ Params = {'Bucket' : BUCKET_LOCATION , 'Key' : parsed_item ['plotting_data_link' ]},
378386 ExpiresIn = 3 * 60 * 60 )
379387 if parsed_item ['plotting_data_link_low_res' ] != '' : # if empty link, skip
380388 parsed_item ['plotting_data_link_low_res' ] = \
381389 s3_client .generate_presigned_url ('get_object' ,
382- Params = {'Bucket' : 'ibl-dj-external' , 'Key' : parsed_item ['plotting_data_link_low_res' ]},
390+ Params = {'Bucket' : BUCKET_LOCATION , 'Key' : parsed_item ['plotting_data_link_low_res' ]},
383391 ExpiresIn = 3 * 60 * 60 )
384392 if parsed_item ['plotting_data_link_very_low_res' ] != '' : # if empty link, skip
385393 parsed_item ['plotting_data_link_very_low_res' ] = \
386394 s3_client .generate_presigned_url ('get_object' ,
387- Params = {'Bucket' : 'ibl-dj-external' , 'Key' : parsed_item ['plotting_data_link_very_low_res' ]},
395+ Params = {'Bucket' : BUCKET_LOCATION , 'Key' : parsed_item ['plotting_data_link_very_low_res' ]},
388396 ExpiresIn = 3 * 60 * 60 )
389397 parsed_items .append (parsed_item )
390398 return parsed_items
@@ -397,7 +405,7 @@ def post_process(ret):
397405 if parsed_item ['plotting_data_link' ] != '' : # if empty link, skip
398406 parsed_item ['plotting_data_link' ] = \
399407 s3_client .generate_presigned_url ('get_object' ,
400- Params = {'Bucket' : 'ibl-dj-external' , 'Key' : parsed_item ['plotting_data_link' ]},
408+ Params = {'Bucket' : BUCKET_LOCATION , 'Key' : parsed_item ['plotting_data_link' ]},
401409 ExpiresIn = 3 * 60 * 60 )
402410 parsed_items .append (parsed_item )
403411 return parsed_items
@@ -410,7 +418,7 @@ def post_process(ret):
410418 if parsed_item ['plotting_data_link' ] != '' : # if empty link, skip
411419 parsed_item ['plotting_data_link' ] = \
412420 s3_client .generate_presigned_url ('get_object' ,
413- Params = {'Bucket' : 'ibl-dj-external' , 'Key' : parsed_item ['plotting_data_link' ]},
421+ Params = {'Bucket' : BUCKET_LOCATION , 'Key' : parsed_item ['plotting_data_link' ]},
414422 ExpiresIn = 3 * 60 * 60 )
415423 parsed_items .append (parsed_item )
416424 return parsed_items
@@ -423,7 +431,7 @@ def post_process(ret):
423431 if parsed_item ['plotting_data_link' ] != '' : # if empty link, skip
424432 parsed_item ['plotting_data_link' ] = \
425433 s3_client .generate_presigned_url ('get_object' ,
426- Params = {'Bucket' : 'ibl-dj-external' , 'Key' : parsed_item ['plotting_data_link' ]},
434+ Params = {'Bucket' : BUCKET_LOCATION , 'Key' : parsed_item ['plotting_data_link' ]},
427435 ExpiresIn = 3 * 60 * 60 )
428436 parsed_items .append (parsed_item )
429437 return parsed_items
@@ -436,7 +444,7 @@ def post_process(ret):
436444 if parsed_item ['plotting_data_link' ] != '' : # if empty link, skip
437445 parsed_item ['plotting_data_link' ] = \
438446 s3_client .generate_presigned_url ('get_object' ,
439- Params = {'Bucket' : 'ibl-dj-external' , 'Key' : parsed_item ['plotting_data_link' ]},
447+ Params = {'Bucket' : BUCKET_LOCATION , 'Key' : parsed_item ['plotting_data_link' ]},
440448 ExpiresIn = 3 * 60 * 60 )
441449 parsed_items .append (parsed_item )
442450 return parsed_items
@@ -453,7 +461,7 @@ def post_process(ret):
453461 if parsed_item ['subject_spinning_brain_link' ] != '' : # if empty link, skip
454462 parsed_item ['subject_spinning_brain_link' ] = \
455463 s3_client .generate_presigned_url ('get_object' ,
456- Params = {'Bucket' : 'ibl-dj-external' , 'Key' : parsed_item ['subject_spinning_brain_link' ]},
464+ Params = {'Bucket' : BUCKET_LOCATION , 'Key' : parsed_item ['subject_spinning_brain_link' ]},
457465 ExpiresIn = 3 * 60 * 60 )
458466 parsed_items .append (parsed_item )
459467 return parsed_items
@@ -466,7 +474,7 @@ def post_process(ret):
466474 if parsed_item ['probe_trajectory_coronal_link' ] != '' : # if empty link, skip
467475 parsed_item ['probe_trajectory_coronal_link' ] = \
468476 s3_client .generate_presigned_url ('get_object' ,
469- Params = {'Bucket' : 'ibl-dj-external' , 'Key' : parsed_item ['probe_trajectory_coronal_link' ]},
477+ Params = {'Bucket' : BUCKET_LOCATION , 'Key' : parsed_item ['probe_trajectory_coronal_link' ]},
470478 ExpiresIn = 3 * 60 * 60 )
471479 parsed_items .append (parsed_item )
472480 return parsed_items
0 commit comments