Skip to content
Snippets Groups Projects
Commit 26554da5 authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Fix example patterns, add debug log

parent 0a2f0151
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,8 @@ path = "visitors.db"
# A list of possible regex patterns for the id (logical OR!)
id_patterns = [
"[A-z0-9]{24}",
"[A-Z0-9]{6,8}",
"^[A-z0-9]{24}$",
"^[A-Z0-9]{6,8}$",
]
# minimum and maximum lengths for the received strings
......@@ -192,7 +192,11 @@ def id_pattern_check(visitor_id: str) -> bool:
Returns True if any of the patterns from the config matches.
Returns False if none of the patterns matches.
"""
return any([re.match(p, visitor_id) for p in config["database"]["id_patterns"]])
matches = []
for match, pattern in [(re.match(pattern, visitor_id) is not None, pattern) for pattern in config["database"]["id_patterns"]]:
app.logger.debug('{} + {} = {}'.format(visitor_id, pattern, match))
matches.append(match)
return any(matches)
def length_check(data: dict, key: str, minimum: int, maximum: int) -> bool:
......@@ -210,9 +214,12 @@ def length_check(data: dict, key: str, minimum: int, maximum: int) -> bool:
return True
# This gets run for each request
@app.route('/', methods = ['POST'])
def post():
"""
This function runs when a POST request on / is received
"""
if not request.data:
# Missing data body, reject
app.logger.info('400, Missing data body')
......@@ -240,6 +247,10 @@ def post():
# This gets run for each request
@app.route('/', methods = ['GET'])
def get():
"""
This function runs when a GET request on / is received.
Can be deactivated in the config with the ignore_get_requests setting
"""
if config["application"]["ignore_get_requests"]:
app.logger.info('501, Get Request Ignored')
return "", 501
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment