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)
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)