Exemple #1
0
    def process_request(self, req, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        validation.validate_table_name(table_name)

        params = req.params.copy()

        # exclusive_start_backup_id = params.pop(
        #     parser.Props.EXCLUSIVE_START_BACKUP_ID, None)

        limit = params.pop(parser.Props.LIMIT, None)
        if limit:
            limit = validation.validate_integer(limit, parser.Props.LIMIT,
                                                min_val=0)

        backups = []
        response = {}

        if backups and str(limit) == str(len(backups)):
            response[parser.Props.LAST_EVALUATED_BACKUP_ID] = backups[-1].id

        self_link_prefix = req.path_url

        response[parser.Props.BACKUPS] = [
            parser.Parser.format_backup(backup, self_link_prefix)
            for backup in backups
        ]

        return response
Exemple #2
0
    def process_request(self, req, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        validation.validate_table_name(table_name)

        params = req.params.copy()

        # exclusive_start_restore_job_id = params.pop(
        #     parser.Props.EXCLUSIVE_START_RESTORE_JOB_ID, None)

        limit = params.pop(parser.Props.LIMIT, None)
        if limit:
            limit = validation.validate_integer(limit,
                                                parser.Props.LIMIT,
                                                min_val=0)

        restore_jobs = []
        response = {}

        if restore_jobs and str(limit) == str(len(restore_jobs)):
            response[parser.Props.
                     LAST_EVALUATED_RESTORE_JOB_ID] = restore_jobs[-1].id

        self_link_prefix = req.path_url

        response[parser.Props.RESTORE_JOBS] = [
            parser.Parser.format_restore_job(restore_job, self_link_prefix)
            for restore_job in restore_jobs
        ]

        return response
Exemple #3
0
    def list_tables(self, req, project_id):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        params = req.params.copy()

        exclusive_start_table_name = params.pop(
            parser.Props.EXCLUSIVE_START_TABLE_NAME, None)
        if exclusive_start_table_name:
            validation.validate_table_name(exclusive_start_table_name)

        limit = params.pop(parser.Props.LIMIT, None)
        if limit:
            limit = validation.validate_integer(limit,
                                                parser.Props.LIMIT,
                                                min_val=0)

        validation.validate_unexpected_props(params, "params")

        table_names = (storage.list_tables(
            req.context,
            exclusive_start_table_name=exclusive_start_table_name,
            limit=limit))

        res = {}

        if table_names and str(limit) == str(len(table_names)):
            res[parser.Props.LAST_EVALUATED_TABLE_NAME] = table_names[-1]

        res["tables"] = [{"rel": "self", "href": name} for name in table_names]

        return res
Exemple #4
0
def list_tables(req, project_id):
    """Returns an array of table describing info associated
    with the current user in given tenant.
    """
    params = req.params.copy()

    exclusive_start_table_name = params.pop(
        parser.Props.EXCLUSIVE_START_TABLE_NAME, None)
    if exclusive_start_table_name:
        validation.validate_table_name(exclusive_start_table_name)

    limit = params.pop(parser.Props.LIMIT, None)
    if limit:
        limit = validation.validate_integer(limit, parser.Props.LIMIT,
                                            min_val=0)

    validation.validate_unexpected_props(params, "params")

    table_names = (
        storage.list_tables(
            project_id,
            exclusive_start_table_name=exclusive_start_table_name,
            limit=limit
        )
    )

    res = {}

    if table_names and str(limit) == str(len(table_names)):
        res[parser.Props.LAST_EVALUATED_TABLE_NAME] = table_names[-1]

    res["tables"] = [{"rel": "self", "href": "{url}/{name}".format(
        url=req.path_url, name=name)} for name in table_names]

    return res
    def list_tables(self, req, project_id):
        LOG.debug(req.path_url)
        req.context.tenant = project_id

        params = req.params.copy()

        exclusive_start_table_name = params.pop(
            parser.Props.EXCLUSIVE_START_TABLE_NAME, None)
        if exclusive_start_table_name:
            validation.validate_table_name(exclusive_start_table_name)

        limit = params.pop(parser.Props.LIMIT, None)
        if limit:
            limit = validation.validate_integer(limit, parser.Props.LIMIT,
                                                min_val=0)

        validation.validate_unexpected_props(params, "params")

        table_names = (
            storage.list_tables(
                req.context,
                exclusive_start_table_name=exclusive_start_table_name,
                limit=limit
            )
        )

        res = {}

        if table_names and str(limit) == str(len(table_names)):
            res[parser.Props.LAST_EVALUATED_TABLE_NAME] = table_names[-1]

        res["tables"] = [{"rel": "self", "href": "{url}/{name}".format(
            url=req.path_url, name=name)} for name in table_names]

        return res
    def process_request(self, req, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        validation.validate_table_name(table_name)

        params = req.params.copy()

        # exclusive_start_restore_job_id = params.pop(
        #     parser.Props.EXCLUSIVE_START_RESTORE_JOB_ID, None)

        limit = params.pop(parser.Props.LIMIT, None)
        if limit:
            limit = validation.validate_integer(limit, parser.Props.LIMIT,
                                                min_val=0)

        restore_jobs = []
        response = {}

        if restore_jobs and str(limit) == str(len(restore_jobs)):
            response[
                parser.Props.LAST_EVALUATED_RESTORE_JOB_ID
            ] = restore_jobs[-1].id

        self_link_prefix = req.path_url

        response[parser.Props.RESTORE_JOBS] = [
            parser.Parser.format_restore_job(restore_job, self_link_prefix)
            for restore_job in restore_jobs
        ]

        return response
Exemple #7
0
    def process_request(self, req, body, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        with probe.Probe(__name__ + '.validation'):
            validation.validate_object(body, "body")

            expected = body.pop(parser.Props.EXPECTED, {})
            validation.validate_object(expected, parser.Props.EXPECTED)
            # parse expected item conditions
            expected_item_conditions = (
                parser.Parser.parse_expected_attribute_conditions(expected)
            )

            item = body.pop(parser.Props.ITEM, None)
            validation.validate_object(item, parser.Props.ITEM)
            # parse item
            item_attributes = parser.Parser.parse_item_attributes(item)

            # parse return_values param
            return_values_json = body.pop(
                parser.Props.RETURN_VALUES, parser.Values.RETURN_VALUES_NONE
            )

            validation.validate_string(return_values_json,
                                       parser.Props.RETURN_VALUES)

            return_values = InsertReturnValuesType(return_values_json)

            # parse return_values param
            time_to_live = body.pop(
                parser.Props.TIME_TO_LIVE, None
            )

            if time_to_live is not None:
                time_to_live = validation.validate_integer(
                    time_to_live, parser.Props.TIME_TO_LIVE, min_val=0
                )

            validation.validate_unexpected_props(body, "body")

        # put item
        result, old_item = storage.put_item(
            req.context, table_name, item_attributes,
            return_values=return_values,
            if_not_exist=False,
            expected_condition_map=expected_item_conditions,
        )

        response = {}

        if old_item:
            response[parser.Props.ATTRIBUTES] = (
                parser.Parser.format_item_attributes(old_item)
            )

        return response
Exemple #8
0
    def process_request(self, req, body, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        with probe.Probe(__name__ + '.validation'):
            validation.validate_object(body, "body")

            expected = body.pop(parser.Props.EXPECTED, {})
            validation.validate_object(expected, parser.Props.EXPECTED)
            # parse expected item conditions
            expected_item_conditions = (
                parser.Parser.parse_expected_attribute_conditions(expected))

            item = body.pop(parser.Props.ITEM, None)
            validation.validate_object(item, parser.Props.ITEM)
            # parse item
            item_attributes = parser.Parser.parse_item_attributes(item)

            # parse return_values param
            return_values_json = body.pop(parser.Props.RETURN_VALUES,
                                          parser.Values.RETURN_VALUES_NONE)

            validation.validate_string(return_values_json,
                                       parser.Props.RETURN_VALUES)

            return_values = InsertReturnValuesType(return_values_json)

            # parse return_values param
            time_to_live = body.pop(parser.Props.TIME_TO_LIVE, None)

            if time_to_live is not None:
                time_to_live = validation.validate_integer(
                    time_to_live, parser.Props.TIME_TO_LIVE, min_val=0)

            validation.validate_unexpected_props(body, "body")

        # put item
        result, old_item = storage.put_item(
            req.context,
            table_name,
            item_attributes,
            return_values=return_values,
            if_not_exist=False,
            expected_condition_map=expected_item_conditions,
        )

        response = {}

        if old_item:
            response[parser.Props.ATTRIBUTES] = (
                parser.Parser.format_item_attributes(old_item))

        return response
Exemple #9
0
def list_backups(req, project_id, table_name):
    """List the backups."""

    utils.check_project_id(project_id)

    with probe.Probe(__name__ + '.validation'):
        validation.validate_table_name(table_name)

        params = req.params.copy()

        exclusive_start_backup_id = params.pop(
            parser.Props.EXCLUSIVE_START_BACKUP_ID, None)

        if exclusive_start_backup_id:
            exclusive_start_backup_id = uuid.UUID(
                exclusive_start_backup_id
            )

        limit = params.pop(parser.Props.LIMIT, None)
        if limit:
            limit = validation.validate_integer(limit, parser.Props.LIMIT,
                                                min_val=0)

    backups = storage.list_backups(
        project_id, table_name, exclusive_start_backup_id, limit)

    response = {}

    if backups and limit == len(backups):
        response[parser.Props.LAST_EVALUATED_BACKUP_ID] = (
            backups[-1].id.hex)

    self_link_prefix = req.path_url

    response[parser.Props.BACKUPS] = [
        parser.Parser.format_backup(backup, self_link_prefix)
        for backup in backups
    ]

    return response
Exemple #10
0
    def process_request(self, req, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        with probe.Probe(__name__ + '.validation'):
            validation.validate_table_name(table_name)

            params = req.params.copy()

            exclusive_start_backup_id = params.pop(
                parser.Props.EXCLUSIVE_START_BACKUP_ID, None)

            if exclusive_start_backup_id:
                exclusive_start_backup_id = uuid.UUID(
                    exclusive_start_backup_id)

            limit = params.pop(parser.Props.LIMIT, None)
            if limit:
                limit = validation.validate_integer(limit,
                                                    parser.Props.LIMIT,
                                                    min_val=0)

        backups = storage.list_backups(req.context, table_name,
                                       exclusive_start_backup_id, limit)

        response = {}

        if backups and limit == len(backups):
            response[parser.Props.LAST_EVALUATED_BACKUP_ID] = (
                backups[-1].id.hex)

        self_link_prefix = req.path_url

        response[parser.Props.BACKUPS] = [
            parser.Parser.format_backup(backup, self_link_prefix)
            for backup in backups
        ]

        return response
def list_restore_jobs(req, project_id, table_name):
    """List restore jobs."""

    utils.check_project_id(project_id)

    validation.validate_table_name(table_name)

    params = req.params.copy()

    exclusive_start_restore_job_id = params.pop(
        parser.Props.EXCLUSIVE_START_RESTORE_JOB_ID, None)
    if exclusive_start_restore_job_id:
        exclusive_start_restore_job_id = uuid.UUID(
            exclusive_start_restore_job_id
        )

    limit = params.pop(parser.Props.LIMIT, None)
    if limit:
        limit = validation.validate_integer(limit, parser.Props.LIMIT,
                                            min_val=0)

    restore_jobs = storage.list_restore_jobs(
        project_id, table_name, exclusive_start_restore_job_id, limit)

    response = {}

    if restore_jobs and limit == len(restore_jobs):
        response[
            parser.Props.LAST_EVALUATED_RESTORE_JOB_ID
        ] = restore_jobs[-1].id.hex

    self_link_prefix = req.path_url

    response[parser.Props.RESTORE_JOBS] = [
        parser.Parser.format_restore_job(restore_job, self_link_prefix)
        for restore_job in restore_jobs
    ]

    return response
Exemple #12
0
    def scan(self, req, body, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        with probe.Probe(__name__ + '.validation'):
            validation.validate_object(body, "body")

            # get attributes_to_get
            attributes_to_get = body.pop(parser.Props.ATTRIBUTES_TO_GET, None)
            if attributes_to_get:
                validation.validate_list(attributes_to_get,
                                         parser.Props.ATTRIBUTES_TO_GET)
                for attr_name in attributes_to_get:
                    validation.validate_attr_name(attr_name)

            select = body.pop(parser.Props.SELECT, None)

            if select is None:
                if attributes_to_get:
                    select = models.SelectType.SELECT_TYPE_SPECIFIC
                else:
                    select = models.SelectType.SELECT_TYPE_ALL
            else:
                validation.validate_string(select, parser.Props.SELECT)
            select_type = models.SelectType(select, attributes_to_get)

            limit = body.pop(parser.Props.LIMIT, None)
            if limit is not None:
                limit = validation.validate_integer(limit, parser.Props.LIMIT,
                                                    min_val=0)

            # parse exclusive_start_key_attributes
            exclusive_start_key_attributes_json = body.pop(
                parser.Props.EXCLUSIVE_START_KEY, None)
            if exclusive_start_key_attributes_json is not None:
                validation.validate_object(exclusive_start_key_attributes_json,
                                           parser.Props.EXCLUSIVE_START_KEY)
                exclusive_start_key_attributes = (
                    parser.Parser.parse_item_attributes(
                        exclusive_start_key_attributes_json
                    )
                )
            else:
                exclusive_start_key_attributes = None

            scan_filter_json = body.pop(parser.Props.SCAN_FILTER, None)
            if scan_filter_json:
                validation.validate_object(scan_filter_json,
                                           parser.Props.SCAN_FILTER)

                condition_map = parser.Parser.parse_attribute_conditions(
                    scan_filter_json, condition_class=ScanCondition
                )
            else:
                condition_map = None

            total_segments = body.pop(parser.Props.TOTAL_SEGMENTS, 1)
            total_segments = validation.validate_integer(
                total_segments, parser.Props.TOTAL_SEGMENTS, min_val=1,
                max_val=4096
            )

            segment = body.pop(parser.Props.SEGMENT, 0)
            segment = validation.validate_integer(
                segment, parser.Props.SEGMENT, min_val=0,
                max_val=total_segments
            )

            validation.validate_unexpected_props(body, "body")

        result = storage.scan(
            req.context, table_name, condition_map,
            attributes_to_get=attributes_to_get, limit=limit,
            exclusive_start_key=exclusive_start_key_attributes)

        response = {
            parser.Props.COUNT: result.count,
            parser.Props.SCANNED_COUNT: result.scanned_count
        }

        if not select_type.is_count:
            response[parser.Props.ITEMS] = [
                parser.Parser.format_item_attributes(row)
                for row in result.items]

        if result.last_evaluated_key:
            response[parser.Props.LAST_EVALUATED_KEY] = (
                parser.Parser.format_item_attributes(
                    result.last_evaluated_key
                )
            )

        return response
Exemple #13
0
    def scan(self, req, body, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        with probe.Probe(__name__ + '.validation'):
            validation.validate_object(body, "body")

            # get attributes_to_get
            attributes_to_get = body.pop(parser.Props.ATTRIBUTES_TO_GET, None)
            if attributes_to_get:
                validation.validate_list(attributes_to_get,
                                         parser.Props.ATTRIBUTES_TO_GET)
                for attr_name in attributes_to_get:
                    validation.validate_attr_name(attr_name)

            select = body.pop(parser.Props.SELECT, None)

            if select is None:
                if attributes_to_get:
                    select = models.SelectType.SELECT_TYPE_SPECIFIC
                else:
                    select = models.SelectType.SELECT_TYPE_ALL
            else:
                validation.validate_string(select, parser.Props.SELECT)
            select_type = models.SelectType(select, attributes_to_get)

            limit = body.pop(parser.Props.LIMIT, None)
            if limit is not None:
                limit = validation.validate_integer(limit,
                                                    parser.Props.LIMIT,
                                                    min_val=0)

            # parse exclusive_start_key_attributes
            exclusive_start_key_attributes_json = body.pop(
                parser.Props.EXCLUSIVE_START_KEY, None)
            if exclusive_start_key_attributes_json is not None:
                validation.validate_object(exclusive_start_key_attributes_json,
                                           parser.Props.EXCLUSIVE_START_KEY)
                exclusive_start_key_attributes = (
                    parser.Parser.parse_item_attributes(
                        exclusive_start_key_attributes_json))
            else:
                exclusive_start_key_attributes = None

            scan_filter_json = body.pop(parser.Props.SCAN_FILTER, None)
            if scan_filter_json:
                validation.validate_object(scan_filter_json,
                                           parser.Props.SCAN_FILTER)

                condition_map = parser.Parser.parse_attribute_conditions(
                    scan_filter_json, condition_class=ScanCondition)
            else:
                condition_map = None

            total_segments = body.pop(parser.Props.TOTAL_SEGMENTS, 1)
            total_segments = validation.validate_integer(
                total_segments,
                parser.Props.TOTAL_SEGMENTS,
                min_val=1,
                max_val=4096)

            segment = body.pop(parser.Props.SEGMENT, 0)
            segment = validation.validate_integer(segment,
                                                  parser.Props.SEGMENT,
                                                  min_val=0,
                                                  max_val=total_segments)

            validation.validate_unexpected_props(body, "body")

        result = storage.scan(
            req.context,
            table_name,
            condition_map,
            attributes_to_get=attributes_to_get,
            limit=limit,
            exclusive_start_key=exclusive_start_key_attributes)

        response = {
            parser.Props.COUNT: result.count,
            parser.Props.SCANNED_COUNT: result.scanned_count
        }

        if not select_type.is_count:
            response[parser.Props.ITEMS] = [
                parser.Parser.format_item_attributes(row)
                for row in result.items
            ]

        if result.last_evaluated_key:
            response[parser.Props.LAST_EVALUATED_KEY] = (
                parser.Parser.format_item_attributes(
                    result.last_evaluated_key))

        return response
Exemple #14
0
    def query(self, req, body, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        with probe.Probe(__name__ + '.validation'):
            validation.validate_object(body, "body")

            # get attributes_to_get
            attributes_to_get = body.pop(parser.Props.ATTRIBUTES_TO_GET, None)
            if attributes_to_get:
                validation.validate_list(attributes_to_get,
                                         parser.Props.ATTRIBUTES_TO_GET)
                for attr_name in attributes_to_get:
                    validation.validate_attr_name(attr_name)

            index_name = body.pop(parser.Props.INDEX_NAME, None)
            if index_name is not None:
                validation.validate_index_name(index_name)

            select = body.pop(parser.Props.SELECT, None)

            if select is None:
                if attributes_to_get:
                    select = models.SelectType.SELECT_TYPE_SPECIFIC
                else:
                    if index_name is not None:
                        select = models.SelectType.SELECT_TYPE_ALL_PROJECTED
                    else:
                        select = models.SelectType.SELECT_TYPE_ALL
            else:
                validation.validate_string(select, parser.Props.SELECT)

            select_type = models.SelectType(select, attributes_to_get)

            # parse exclusive_start_key_attributes
            exclusive_start_key_attributes_json = body.pop(
                parser.Props.EXCLUSIVE_START_KEY, None)

            if exclusive_start_key_attributes_json is not None:
                validation.validate_object(exclusive_start_key_attributes_json,
                                           parser.Props.EXCLUSIVE_START_KEY)
                exclusive_start_key_attributes = (
                    parser.Parser.parse_item_attributes(
                        exclusive_start_key_attributes_json
                    )
                )
            else:
                exclusive_start_key_attributes = None

            # parse indexed_condition_map
            key_conditions = body.pop(parser.Props.KEY_CONDITIONS, None)
            validation.validate_object(key_conditions,
                                       parser.Props.KEY_CONDITIONS)

            indexed_condition_map = parser.Parser.parse_attribute_conditions(
                key_conditions, condition_class=IndexedCondition
            )

            # TODO(dukhlov):
            # it would be nice to validate given table_name, key_attributes and
            # attributes_to_get to schema expectation

            consistent_read = body.pop(parser.Props.CONSISTENT_READ, False)
            validation.validate_boolean(consistent_read,
                                        parser.Props.CONSISTENT_READ)
            limit = body.pop(parser.Props.LIMIT, None)
            if limit is not None:
                limit = validation.validate_integer(limit, parser.Props.LIMIT,
                                                    min_val=0)

            scan_forward = body.pop(parser.Props.SCAN_INDEX_FORWARD, None)

            if scan_forward is not None:
                validation.validate_boolean(scan_forward,
                                            parser.Props.SCAN_INDEX_FORWARD)
                order_type = (
                    models.ORDER_TYPE_ASC if scan_forward else
                    models.ORDER_TYPE_DESC
                )
            else:
                order_type = None

            validation.validate_unexpected_props(body, "body")

        # select item
        result = storage.select_item(
            req.context, table_name, indexed_condition_map,
            select_type=select_type, index_name=index_name, limit=limit,
            consistent=consistent_read, order_type=order_type,
            exclusive_start_key=exclusive_start_key_attributes
        )

        # format response
        if select_type.type == models.SelectType.SELECT_TYPE_COUNT:
            response = {
                parser.Props.COUNT: result.count
            }
        else:
            response = {
                parser.Props.COUNT: result.count,
                parser.Props.ITEMS: [
                    parser.Parser.format_item_attributes(row)
                    for row in result.items
                ]
            }

        if limit == result.count:
            response[parser.Props.LAST_EVALUATED_KEY] = (
                parser.Parser.format_item_attributes(
                    result.last_evaluated_key)
            )

        return response
Exemple #15
0
    def query(self, req, body, project_id, table_name):
        with probe.Probe(__name__ + '.validation'):
            validation.validate_object(body, "body")

            # get attributes_to_get
            attributes_to_get = body.pop(parser.Props.ATTRIBUTES_TO_GET, None)
            if attributes_to_get is not None:
                validation.validate_list(attributes_to_get,
                                         parser.Props.ATTRIBUTES_TO_GET)
                for attr_name in attributes_to_get:
                    validation.validate_attr_name(attr_name)

            index_name = body.pop(parser.Props.INDEX_NAME, None)
            if index_name is not None:
                validation.validate_index_name(index_name)

            select = body.pop(parser.Props.SELECT, None)

            if select is None:
                if attributes_to_get:
                    select = models.SelectType.SELECT_TYPE_SPECIFIC
                else:
                    if index_name is not None:
                        select = models.SelectType.SELECT_TYPE_ALL_PROJECTED
                    else:
                        select = models.SelectType.SELECT_TYPE_ALL
            else:
                validation.validate_string(select, parser.Props.SELECT)

            select_type = models.SelectType(select, attributes_to_get)

            # parse exclusive_start_key_attributes
            exclusive_start_key_attributes_json = body.pop(
                parser.Props.EXCLUSIVE_START_KEY, None)

            if exclusive_start_key_attributes_json is not None:
                validation.validate_object(exclusive_start_key_attributes_json,
                                           parser.Props.EXCLUSIVE_START_KEY)
                exclusive_start_key_attributes = (
                    parser.Parser.parse_item_attributes(
                        exclusive_start_key_attributes_json))
            else:
                exclusive_start_key_attributes = None

            # parse indexed_condition_map
            key_conditions = body.pop(parser.Props.KEY_CONDITIONS, None)
            validation.validate_object(key_conditions,
                                       parser.Props.KEY_CONDITIONS)

            indexed_condition_map = parser.Parser.parse_attribute_conditions(
                key_conditions, condition_class=IndexedCondition)

            # TODO(dukhlov):
            # it would be nice to validate given table_name, key_attributes and
            # attributes_to_get to schema expectation

            consistent_read = body.pop(parser.Props.CONSISTENT_READ, False)
            validation.validate_boolean(consistent_read,
                                        parser.Props.CONSISTENT_READ)
            limit = body.pop(parser.Props.LIMIT, None)
            if limit is not None:
                limit = validation.validate_integer(limit,
                                                    parser.Props.LIMIT,
                                                    min_val=0)

            scan_forward = body.pop(parser.Props.SCAN_INDEX_FORWARD, None)

            if scan_forward is not None:
                validation.validate_boolean(scan_forward,
                                            parser.Props.SCAN_INDEX_FORWARD)
                order_type = (models.ORDER_TYPE_ASC
                              if scan_forward else models.ORDER_TYPE_DESC)
            else:
                order_type = None

            validation.validate_unexpected_props(body, "body")

        # select item
        result = storage.query(
            req.context,
            table_name,
            indexed_condition_map,
            select_type=select_type,
            index_name=index_name,
            limit=limit,
            consistent=consistent_read,
            order_type=order_type,
            exclusive_start_key=exclusive_start_key_attributes)

        # format response
        if select_type.type == models.SelectType.SELECT_TYPE_COUNT:
            response = {parser.Props.COUNT: result.count}
        else:
            response = {
                parser.Props.COUNT:
                result.count,
                parser.Props.ITEMS: [
                    parser.Parser.format_item_attributes(row)
                    for row in result.items
                ]
            }

        if limit == result.count:
            response[parser.Props.LAST_EVALUATED_KEY] = (
                parser.Parser.format_item_attributes(
                    result.last_evaluated_key))

        return response