# Path: protector/influxdb/keyword.py
# class Keyword:
#     """
#     Valid InfluxDB Keywords
#     """
# 
#     SELECT = 'select'
#     FROM = 'from'
#     WHERE = 'where'
#     LIMIT = 'limit'
#     ORDER = 'order'
#     GROUP_BY = 'group'
#     DROP = 'drop'
#     DELETE = 'delete'
#     LIST = 'list'
#     SERIES = 'series'
# 
#     def __init__(self):
#         pass
# 
# Path: protector/rules/rule.py
# class Rule(object):
#     @staticmethod
#     def description():
#         """
#         :return: A short description of the rule
#         """
#         pass
# 
#     @staticmethod
#     def reason():
#         """
#         When and why the rule is useful.
# 
#         This should return a list of lines instead of a long string.
#         It's easier to format line breaks this way.
# 
#         :return: The reason for the rule
#         """
#         pass
# 
#     def check(self, query):
#         """
#         Check if a given query is permitted
#         :param query:
#         :return: result.Ok() if permitted, result.Err() if not.
#         """
#         pass


from result import Ok, Err
from protector.influxdb.keyword import Keyword
from protector.rules.rule import Rule



class RuleChecker(Rule):
    def __init__(self):
        # Todo: Make this configurable from config file
        self.max_datapoints = 9000

    @staticmethod
    def description():
        return "Prevent too many datapoints per query"

    @staticmethod
    def reason():
        return ["Such queries can bring down the time series database",
                "or overload the client with too much data transferred over the wire."]

    def check(self, query):
        """
        :param query:
        """

# Path: protector/influxdb/keyword.py
# class Keyword:
#     """
#     Valid InfluxDB Keywords
#     """
# 
#     SELECT = 'select'
#     FROM = 'from'
#     WHERE = 'where'
#     LIMIT = 'limit'
#     ORDER = 'order'
#     GROUP_BY = 'group'
#     DROP = 'drop'
#     DELETE = 'delete'
#     LIST = 'list'
#     SERIES = 'series'
# 
#     def __init__(self):
#         pass
# 
# Path: protector/rules/rule.py
# class Rule(object):
#     @staticmethod
#     def description():
#         """
#         :return: A short description of the rule
#         """
#         pass
# 
#     @staticmethod
#     def reason():
#         """
#         When and why the rule is useful.
# 
#         This should return a list of lines instead of a long string.
#         It's easier to format line breaks this way.
# 
#         :return: The reason for the rule
#         """
#         pass
# 
#     def check(self, query):
#         """
#         Check if a given query is permitted
#         :param query:
#         :return: result.Ok() if permitted, result.Err() if not.
#         """
#         pass


# Path: protector/rules/too_many_datapoints.py
from result import Ok, Err
from protector.influxdb.keyword import Keyword
from protector.rules.rule import Rule




class RuleChecker(Rule):
    def __init__(self):
        # Todo: Make this configurable from config file
        self.max_datapoints = 9000

    @staticmethod
    def description():
        return "Prevent too many datapoints per query"

    @staticmethod
    def reason():
        return ["Such queries can bring down the time series database",
                "or overload the client with too much data transferred over the wire."]

    def check(self, query):
        """
        :param query:
        """

        if query.get_type() not in {Keyword.SELECT, Keyword.DELETE}: