def authorize_run_listing(project_id): logger.info("Looking up project") # Check the project resource exists abort_if_project_doesnt_exist(project_id) if request.headers is None or 'Authorization' not in request.headers: safe_fail_request(401, message="Authentication token required") auth_header = request.headers.get('Authorization') logger.info("Checking credentials to list project runs") # Check the caller has a valid results token (analyst token) abort_if_invalid_results_token(project_id, auth_header) logger.info("Caller is allowed to list project runs")
def get(project_id, run_id): log = logger.bind(pid=project_id, rid=run_id) logger.info("request description of a run") # Check the project and run resources exist abort_if_run_doesnt_exist(project_id, run_id) # Check the caller has a valid results token. Yes it should be renamed. abort_if_invalid_results_token(project_id, request.headers.get('Authorization')) log.info("request for run description authorized") db_conn = db.get_db() run_object = db.get_run(db_conn, run_id) return RunDescription().dump(run_object)
def project_delete(project_id): log = logger.bind(pid=project_id) log.info('Request to delete project') # Check the resource exists and hasn't already been marked for deletion abort_if_project_doesnt_exist(project_id) # Check the caller has a valid results token. Yes it should be renamed. abort_if_invalid_results_token(project_id, request.headers.get('Authorization')) log.info("Marking project for deletion") with DBConn() as db_conn: db.mark_project_deleted(db_conn, project_id) log.info("Queuing authorized request to delete project resources") remove_project.delay(project_id) return '', 204
def authorise_get_request(project_id): if request.headers is None or 'Authorization' not in request.headers: safe_fail_request(401, message="Authentication token required") auth_header = request.headers.get('Authorization') dp_id = None # Check the resource exists abort_if_project_doesnt_exist(project_id) with DBConn() as dbinstance: project_object = db.get_project(dbinstance, project_id) logger.info("Checking credentials") if project_object['result_type'] == 'mapping' or project_object[ 'result_type'] == 'similarity_scores': # Check the caller has a valid results token if we are including results abort_if_invalid_results_token(project_id, auth_header) elif project_object['result_type'] == 'permutations': dp_id = get_authorization_token_type_or_abort(project_id, auth_header) else: safe_fail_request(500, "Unknown error") return dp_id, project_object
def post(project_id, run): log, span = bind_log_and_span(project_id) log.debug("Processing request to add a new run", run=run) # Check the resource exists abort_if_project_doesnt_exist(project_id) # Check the caller has a valid results token. Yes it should be renamed. abort_if_invalid_results_token(project_id, request.headers.get('Authorization')) abort_if_project_in_error_state(project_id) run_model = Run.from_json(run, project_id) log.debug("Saving run") with db.DBConn() as db_conn: run_model.save(db_conn) check_for_executable_runs.delay(project_id, serialize_span(span)) return RunDescription().dump(run_model), 201
def post(project_id, run): log = logger.bind(pid=project_id) log.debug("Processing request to add a new run", run=run) # Check the resource exists abort_if_project_doesnt_exist(project_id) # Check the caller has a valid results token. Yes it should be renamed. abort_if_invalid_results_token(project_id, request.headers.get('Authorization')) abort_if_project_in_error_state(project_id) run_model = Run.from_json(run, project_id) log.debug("Saving run") with db.DBConn() as db_conn: run_model.save(db_conn) project_object = db.get_project(db_conn, project_id) parties_contributed = db.get_number_parties_uploaded( db_conn, project_id) ready_to_run = parties_contributed == project_object['parties'] log.debug( "Expecting {} parties to upload data. Have received {}".format( project_object['parties'], parties_contributed)) if ready_to_run: log.info( "Scheduling task to carry out all runs for project {} now". format(project_id)) update_run_mark_queued(db_conn, run_model.run_id) else: log.info("Task queued but won't start until CLKs are all uploaded") if ready_to_run: span = g.flask_tracer.get_span() span.set_tag("run_id", run_model.run_id) span.set_tag("project_id", run_model.project_id) check_for_executable_runs.delay(project_id, serialize_span(span)) return RunDescription().dump(run_model), 201
def authorize_run_detail(project_id, run_id): # Check the project and run resources exist abort_if_run_doesnt_exist(project_id, run_id) # Check the caller has a valid results token. Yes it should be renamed. abort_if_invalid_results_token(project_id, request.headers.get('Authorization'))