示例#1
0
    def upload_private_data(self, task, project_id):
        private_fields = task.pop('private_fields', None)
        private_gold_answers = task.pop('private_gold_answers', None)
        if not (private_fields or private_gold_answers):
            return

        encryption = current_app.config.get('ENABLE_ENCRYPTION', False)
        bucket = current_app.config.get("S3_REQUEST_BUCKET")
        task_hash = hashlib.md5(json.dumps(task)).hexdigest()
        path = "{}/{}".format(project_id, task_hash)
        s3_conn_type = current_app.config.get('S3_CONN_TYPE')
        if private_fields:
            file_name = 'task_private_data.json'
            values = dict(store=s3_conn_type, bucket=bucket, project_id=project_id, path='{}/{}'.format(task_hash, file_name))
            private_json__upload_url = url_for('fileproxy.encrypted_file', **values)
            upload_json_data(bucket=bucket,
                json_data=private_fields, upload_path=path,
                file_name=file_name, encryption=encryption,
                conn_name='S3_TASK_REQUEST')
            task['info']['private_json__upload_url'] = private_json__upload_url

        if private_gold_answers:
            file_name = 'task_private_gold_answer.json'
            values = dict(store=s3_conn_type, bucket=bucket, project_id=project_id, path='{}/{}'.format(task_hash, file_name))
            gold_answers_url = url_for('fileproxy.encrypted_file', **values)
            upload_json_data(bucket=bucket,
                json_data=private_gold_answers, upload_path=path,
                file_name=file_name, encryption=encryption,
                conn_name='S3_TASK_REQUEST')
            task['gold_answers'] = gold_answers_url
示例#2
0
    def _preprocess_post_data(self, data):
        with_encryption = app.config.get('ENABLE_ENCRYPTION')
        upload_root_dir = app.config.get('S3_UPLOAD_DIRECTORY')
        if current_user.is_anonymous:
            raise Forbidden('')
        task_id = data['task_id']
        project_id = data['project_id']
        self.check_can_post(project_id, task_id)
        preprocess_task_run(project_id, task_id, data)
        if with_encryption:
            info = data['info']
            path = "{0}/{1}/{2}".format(project_id, task_id, current_user.id)

            # for tasks with private_json_encrypted_payload, generate
            # encrypted response payload under private_json__encrypted_response
            encrypted_response = encrypt_task_response_data(task_id, project_id, info)
            data['info'] = {}
            pyb_answer_url = upload_json_data(json_data=info, upload_path=path,
                file_name='pyb_answer.json', encryption=with_encryption,
                conn_name='S3_TASKRUN', upload_root_dir=upload_root_dir
            )
            if pyb_answer_url:
                data['info']['pyb_answer_url'] = pyb_answer_url
            if encrypted_response:
                data['info']['private_json__encrypted_response'] = encrypted_response
示例#3
0
def upload_gold_data(task, project_id, private_gold_answers, file_id=None):
    encryption = current_app.config.get('ENABLE_ENCRYPTION', False)
    bucket = current_app.config.get("S3_REQUEST_BUCKET")
    if file_id:
        task_hash = file_id
    else:
        task_hash = hashlib.md5(json.dumps(task)).hexdigest()
    path = "{}/{}".format(project_id, task_hash)
    s3_conn_type = current_app.config.get('S3_CONN_TYPE')
    file_name = 'task_private_gold_answer.json'
    values = dict(store=s3_conn_type,
                  bucket=bucket,
                  project_id=project_id,
                  path='{}/{}'.format(task_hash, file_name))
    gold_answers_url = url_for('fileproxy.encrypted_file', **values)
    upload_json_data(bucket=bucket,
                     json_data=private_gold_answers,
                     upload_path=path,
                     file_name=file_name,
                     encryption=encryption,
                     conn_name='S3_TASK_REQUEST')

    return gold_answers_url
示例#4
0
def upload_files_priv(task, project_id, data, file_name):
    bucket = bucket_name()
    task_hash = hashlib.md5(str(task)).hexdigest()
    path = "{}/{}".format(project_id, task_hash)
    values = dict(store=s3_conn_type(),
                  bucket=bucket,
                  project_id=project_id,
                  path='{}/{}'.format(task_hash, file_name))
    file_url = url_for('fileproxy.encrypted_file', **values)
    internal_url = upload_json_data(bucket=bucket,
                                    json_data=data,
                                    upload_path=path,
                                    file_name=file_name,
                                    encryption=True,
                                    conn_name='S3_TASK_REQUEST')
    return {'externalUrl': file_url, 'internalUrl': internal_url}
示例#5
0
 def _preprocess_post_data(self, data):
     with_encryption = app.config.get('ENABLE_ENCRYPTION')
     upload_root_dir = app.config.get('S3_UPLOAD_DIRECTORY')
     if current_user.is_anonymous:
         raise Forbidden('')
     task_id = data['task_id']
     project_id = data['project_id']
     self.check_can_post(project_id, task_id)
     preprocess_task_run(project_id, task_id, data)
     info = data['info']
     path = "{0}/{1}/{2}".format(project_id, task_id, current_user.id)
     if with_encryption:
         data['info'] = {
             'pyb_answer_url':
             upload_json_data(json_data=info,
                              upload_path=path,
                              file_name='pyb_answer.json',
                              encryption=with_encryption,
                              conn_name='S3_TASKRUN',
                              upload_root_dir=upload_root_dir)
         }
示例#6
0
 def _preprocess_post_data(self, data):
     if current_user.is_anonymous():
         raise Forbidden('')
     task_id = data['task_id']
     project_id = data['project_id']
     user_id = current_user.id
     self.check_can_post(project_id, task_id, user_id)
     info = data.get('info')
     with_encryption = app.config.get('ENABLE_ENCRYPTION')
     upload_root_dir = app.config.get('S3_UPLOAD_DIRECTORY')
     if info is None:
         return
     path = "{0}/{1}/{2}".format(project_id, task_id, user_id)
     _upload_files_from_json(info, path, with_encryption)
     _upload_files_from_request(info, request.files, path, with_encryption)
     if with_encryption:
         data['info'] = {
             'pyb_answer_url': upload_json_data(json_data=info, upload_path=path,
                 file_name='pyb_answer.json', encryption=with_encryption,
                 conn_name='S3_TASKRUN', upload_root_dir=upload_root_dir)
         }