def data_pipeline_upload(): #Cases: invalid access creds access_key = request.values["access_key"] access_secret = request.values["secret_key"] if not Researcher.objects.filter(access_key_id=access_key).exists(): return abort(403) # access key DNE researcher = Researcher.objects.get(access_key_id=access_key) if not researcher.validate_access_credentials(access_secret): return abort( 403 ) # incorrect secret key # case: invalid study study_id = request.values["study_id"] if not Study.objects.exists(object_id=study_id): return abort(404) study_obj = Study.objects.get(object_id=study_id) # case: study not authorized for user if not study_obj.get_reserachers().filter(id=researcher.id).exists(): return abort(403) # block extra keys errors = [] for key in request.values.iterkeys(): if key not in VALID_PIPELINE_POST_PARAMS: errors.append('encountered invalid parameter: "%s"' % key) if errors: return Response("\n".join(errors), 400) try: creation_args = PipelineUpload.get_creation_arguments(request.values, request.files['file']) except InvalidUploadParameterError as e: return Response(e.message, 400) s3_upload( creation_args['s3_path'], request.files['file'].read(), creation_args['study_id'], raw_path=True ) pipeline_upload = PipelineUpload(creation_args, random_id=True) pipeline_upload.save() return Response("SUCCESS", status=200)
def data_pipeline_upload(): # block extra keys errors = [] for key in request.values.keys(): if key not in VALID_PIPELINE_POST_PARAMS: errors.append('encountered invalid parameter: "%s"' % key) if errors: return Response("\n".join(errors), 400) # the information we need is all gathered from the get_creation_arguments method, use it. try: creation_args, tags = PipelineUpload.get_creation_arguments(request.values, request.files['file']) except InvalidUploadParameterError as e: return Response(str(e), 400) s3_upload( creation_args['s3_path'], request.files['file'].read(), Study.objects.get(id=creation_args['study_id']).object_id, raw_path=True, ) pipeline_upload = PipelineUpload(object_id=PipelineUpload.generate_objectid_string('object_id'), **creation_args) pipeline_upload.save() for tag in tags: pipeline_upload_tag = PipelineUploadTags(pipeline_upload=pipeline_upload, tag=tag) pipeline_upload_tag.save() return Response("SUCCESS", status=200)