Example #1
0
    def validate_answer(self, key, answer):
        if not answer:
            raise ApiError("Missing answer")

        if len(answer) <= 1:
            raise ApiError("Answer is too Short")

        return answer
    def validate_email(self, key, address):
        if not address:
            raise ApiError("Missing email address")

        _, addr = parseaddr(address)
        if not addr:
            raise ApiError("Invalid email address")

        return addr
Example #3
0
    def validate_question(self, key, question):
        if not question:
            raise ApiError("Missing question")

        if len(question) <= 1:
            raise ApiError("Question is too short")

        if question[-1] != "?":
            raise ApiError("Question doesn't end with a question mark")

        return question
Example #4
0
def wrongApiKey():
    """Sends a 401 response"""
    error_detail = {'0': 'Correct ApiKey MUST be provided for authentication.'}
    raise ApiError(code=401,
                   title="Invalid ApiKey",
                   detail=error_detail,
                   source="wrongApiKey()")
Example #5
0
def provideApiKey(endpoint="provideApiKey()"):
    """Sends a 401 response"""
    try:
        endpoint = str(endpoint)
    except Exception as exp:
        logger.debug("Could not convert endpoint to str. Using default value.")
    error_detail = {'0': 'ApiKey MUST be provided for authentication.'}
    raise ApiError(code=401, title="No ApiKey in Request Headers", detail=error_detail, source=endpoint)
 def validate_password(password):
     if not password:
         raise ApiError("Missing password")
     if len(password) < 8:
         raise ApiError("Password is too short")
     return password
 def validate_username(self, key, username):
     if not username:
         raise ApiError("Missing username")
     if not re.match(User.username_regex, username):
         raise ApiError("Invalid username")
     return username
 def validate_name(self, key, name):
     if not name:
         raise ApiError("Missing name")
     return name