コード例 #1
0
    def __init__(self) -> None:
        self.client = get_proxy_client()
        self.parser = reqparse.RequestParser()
        self.parser.add_argument('tag_type', type=str, required=False, default='default')
        super(TableTagAPI, self).__init__()

        self._tag_common = TagCommon(client=self.client)
コード例 #2
0
    def test_badge_on_unreserved_badge_value(self) -> None:
        self.app.config['WHITELIST_BADGES'] = [BADGE_NAME]

        mock_proxy = MagicMock()
        tag_common = TagCommon(client=mock_proxy)
        response = tag_common.put(id='',
                                  resource_type=ResourceType.Dashboard,
                                  tag=TAG_NAME,
                                  tag_type='badge')

        self.assertEqual(response[1], HTTPStatus.NOT_FOUND)
コード例 #3
0
    def test_badge_on_reserved_badge_value(self) -> None:
        self.app.config['WHITELIST_BADGES'] = [
            Badge(badge_name=BADGE_NAME, category='table_status')
        ]

        mock_proxy = MagicMock()
        tag_common = TagCommon(client=mock_proxy)
        response = tag_common.put(id='',
                                  resource_type=ResourceType.Dashboard,
                                  tag=BADGE_NAME,
                                  tag_type='badge')
        self.assertEqual(response[1], HTTPStatus.NOT_ACCEPTABLE)
コード例 #4
0
class TableTagAPI(Resource):
    """
    TableTagAPI that supports GET, PUT and DELETE operation to add or delete tag
    on table
    """
    def __init__(self) -> None:
        self.client = get_proxy_client()
        self.parser = reqparse.RequestParser()
        self.parser.add_argument('tag_type',
                                 type=str,
                                 required=False,
                                 default='default')
        super(TableTagAPI, self).__init__()

        self._tag_common = TagCommon(client=self.client)

    @swag_from('swagger_doc/tag/tag_put.yml')
    def put(self, id: str, tag: str) -> Iterable[Union[Mapping, int, None]]:
        """
        API to add a tag to existing table uri.

        :param table_uri:
        :param tag:
        :return:
        """
        args = self.parser.parse_args()
        # use tag_type to distinguish between tag and badge
        tag_type = args.get('tag_type', 'default')

        return self._tag_common.put(id=id,
                                    resource_type=ResourceType.Table,
                                    tag=tag,
                                    tag_type=tag_type)

    @swag_from('swagger_doc/tag/tag_delete.yml')
    def delete(self, id: str, tag: str) -> Iterable[Union[Mapping, int, None]]:
        """
        API to remove a association between a given tag and a table.

        :param table_uri:
        :param tag:
        :return:
        """
        args = self.parser.parse_args()
        tag_type = args.get('tag_type', 'default')

        return self._tag_common.delete(id=id,
                                       resource_type=ResourceType.Table,
                                       tag=tag,
                                       tag_type=tag_type)
コード例 #5
0
class FeatureTagAPI(Resource):
    """
    Only for user tags not owner tags
    """
    def __init__(self) -> None:
        self.client = get_proxy_client()
        self.parser = reqparse.RequestParser()
        self.parser.add_argument('tag_type',
                                 type=str,
                                 required=False,
                                 default='default')

        self._tag_common = TagCommon(client=self.client)

    @swag_from('swagger_doc/tag/tag_put.yml')
    def put(self, id: str, tag: str) -> Iterable[Union[Mapping, int, None]]:
        args = self.parser.parse_args()
        # use tag_type to distinguish between tag and badge
        tag_type = args.get('tag_type', 'default')

        if tag_type == 'owner':
            LOGGER.error(f'Invalid attempt to add owner tag')
            return \
                {'message': f'The tag {tag} for id {id} with type {tag_type} '
                            f'and resource_type {ResourceType.Feature.name} is '
                            'not added successfully because owner tags are not editable'}, \
                HTTPStatus.CONFLICT

        return self._tag_common.put(id=id,
                                    resource_type=ResourceType.Feature,
                                    tag=tag,
                                    tag_type=tag_type)

    @swag_from('swagger_doc/tag/tag_delete.yml')
    def delete(self, id: str, tag: str) -> Iterable[Union[Mapping, int, None]]:
        args = self.parser.parse_args()
        tag_type = args.get('tag_type', 'default')
        if tag_type == 'owner':
            LOGGER.error(f'Invalid attempt to delete owner tag')
            return \
                {'message': f'The tag {tag} for id {id} with type {tag_type} '
                            f'and resource_type {ResourceType.Feature.name} is '
                            'not deleted because owner tags are not editable'}, \
                HTTPStatus.CONFLICT

        return self._tag_common.delete(id=id,
                                       resource_type=ResourceType.Feature,
                                       tag=tag,
                                       tag_type=tag_type)