Exemple #1
0
def proxy_request(project_id,
                  uuid,
                  data,
                  args,
                  headers,
                  method,
                  action,
                  dry_run=False):
    node = get_node(project_id, uuid)
    check_action_allowed_in_state(action, node.file_state)
    file_record = get_file_record(uuid)

    if dry_run:
        message = (
            "Transaction would have been successful. User selected dry run"
            " option; transaction aborted, no data written to object storage.")
        return flask.Response(json.dumps({"message": message}), status=200)

    if action in ["upload", "initiate_multipart"]:
        update_state(node, UPLOADING_STATE)
    elif action == "abort_multipart":
        update_state(node, submitted_state())

    if action not in [
            "upload", "upload_part", "complete_multipart", "reassign"
    ]:
        data = ""

    if action == "reassign":
        try:
            # data.read() works like a file pointer.
            # When you .read() again it will be pointing at the end of the stream
            json_data = data.read()

            # if it comes in as a string, convert it to dict
            if not isinstance(json_data, dict):
                json_data = json.loads(json_data)

            new_url = json_data["s3_url"]

        except Exception:
            message = "Unable to parse json. Use the format {'s3_url':'s3/://...'}"
            return flask.Response(json.dumps({"message": message}), status=400)

        update_file_record_url(file_record, s3_url=new_url)
        update_state(node, SUCCESS_STATE)
        message = "URL successfully reassigned. New url: {}".format(new_url)
        return flask.Response(json.dumps({"message": message}), status=200)

    resp = s3.make_s3_request(project_id, uuid, data, args, headers, method,
                              action)
    if action in ["upload", "complete_multipart"]:
        if resp.status == 200:
            update_file_record_url(file_record, project_id + "/" + uuid)
            update_state(node, SUCCESS_STATE)
    if action == "delete":
        if resp.status == 204:
            update_state(node, submitted_state())
            update_file_record_url(file_record, None)
    return resp
Exemple #2
0
def proxy_request(project_id,
                  uuid,
                  data,
                  args,
                  headers,
                  method,
                  action,
                  dry_run=False):
    node = get_node(project_id, uuid)
    check_action_allowed_in_state(action, node.file_state)
    signpost_obj = get_signpost(uuid)

    if dry_run:
        message = (
            'Transaction would have been successful. User selected dry run'
            ' option; transaction aborted, no data written to object storage.')
        return flask.Response(json.dumps({'message': message}), status=200)

    if action in ['upload', 'initiate_multipart']:
        update_state(node, UPLOADING_STATE)
    elif action == 'abort_multipart':
        update_state(node, submitted_state())

    if action not in [
            'upload', 'upload_part', 'complete_multipart', 'reassign'
    ]:
        data = ''

    if action == 'reassign':
        try:
            # data.read() works like a file pointer.
            # When you .read() again it will be pointing at the end of the stream
            json_data = data.read()

            # if it comes in as a string, convert it to dict
            if not isinstance(json_data, dict):
                json_data = json.loads(json_data)

            new_url = json_data['s3_url']

        except Exception:
            message = 'Unable to parse json. Use the format {\'s3_url\':\'s3/://...\'}'
            return flask.Response(json.dumps({'message': message}), status=400)

        update_signpost_url(signpost_obj, s3_url=new_url)
        update_state(node, SUCCESS_STATE)
        message = ('URL successfully reassigned. New url: {}'.format(new_url))
        return flask.Response(json.dumps({'message': message}), status=200)

    resp = s3.make_s3_request(project_id, uuid, data, args, headers, method,
                              action)
    if action in ['upload', 'complete_multipart']:
        if resp.status == 200:
            update_signpost_url(signpost_obj, project_id + '/' + uuid)
            update_state(node, SUCCESS_STATE)
    if action == 'delete':
        if resp.status == 204:
            update_state(node, submitted_state())
            update_signpost_url(signpost_obj, None)
    return resp
Exemple #3
0
def proxy_request(project_id,
                  uuid,
                  data,
                  args,
                  headers,
                  method,
                  action,
                  dry_run=False):
    node = get_node(project_id, uuid)
    check_action_allowed_in_state(action, node.file_state)
    signpost_obj = get_signpost(uuid)

    if dry_run:
        message = (
            'Transaction would have been successful. User selected dry run'
            ' option; transaction aborted, no data written to object storage.')
        return flask.Response(json.dumps({'message': message}), status=200)

    if action in ['upload', 'initiate_multipart']:
        update_state(node, UPLOADING_STATE)
    elif action == 'abort_multipart':
        update_state(node, submitted_state())
    if action not in ['upload', 'upload_part', 'complete_multipart']:
        data = ''

    resp = s3.make_s3_request(project_id, uuid, data, args, headers, method,
                              action)
    if action in ['upload', 'complete_multipart']:
        if resp.status == 200:
            update_signpost_url(signpost_obj, project_id + '/' + uuid)
            update_state(node, SUCCESS_STATE)
    if action == 'delete':
        if resp.status == 204:
            update_state(node, submitted_state())
            update_signpost_url(signpost_obj, None)
    return resp
Exemple #4
0
    SUCCESS_STATE,
    ERROR_STATE,
    UPLOADING_PARTS,
)
from sheepdog.utils.transforms.graph_to_doc import (
    entity_to_template,
    entity_to_template_delimited,
    entity_to_template_json,
    entity_to_template_str,
    get_node_category,
)
from . import parse
from . import s3
from . import scheduling

ALLOWED_STATES = [ERROR_STATE, submitted_state(), UPLOADING_STATE]


def _get_links(file_format, schema, exclude_id):
    """
    Parse links from schema.

    we don't have project specific schema now
    so right now this uses top level schema

    TODO
    """
    links = dict()
    subgroups = [link for link in schema if "subgroup" in link]
    non_subgroups = [link for link in schema if "name" in link]
    for link in non_subgroups:
Exemple #5
0
from sheepdog.auth import get_program_project_roles
from sheepdog.globals import (
    submitted_state,
    ALLOWED_DELETION_STATES,
)
from sheepdog.transactions.entity_base import EntityBase, EntityErrors
from sheepdog.transactions.transaction_base import MissingNode

ALLOWED_DELETION_FILE_STATES = [submitted_state(), None]


class DeletionEntity(EntityBase):
    def __init__(self, transaction, node):
        super(DeletionEntity, self).__init__(transaction, node)
        self.action = 'delete'
        self.dependents = {
            # entity.node.node_id: entity
        }

        if isinstance(node, MissingNode):
            self.neighbors = ()
            return

        self.neighbors = (edge.src for edge in node.edges_in)

        # Check user permissions for deleting nodes
        roles = get_program_project_roles(
            *self.transaction.project_id.split('-', 1))
        if 'delete' not in roles:
            self.record_error(
                'You do not have delete permission for project {}'.format(