Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stechuhr-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pandemic_Response
stechuhr-server
Commits
26554da5
Commit
26554da5
authored
4 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Fix example patterns, add debug log
parent
0a2f0151
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
stechuhr_server/server.py
+15
-4
15 additions, 4 deletions
stechuhr_server/server.py
with
15 additions
and
4 deletions
stechuhr_server/server.py
+
15
−
4
View file @
26554da5
...
@@ -23,8 +23,8 @@ path = "visitors.db"
...
@@ -23,8 +23,8 @@ path = "visitors.db"
# A list of possible regex patterns for the id (logical OR!)
# A list of possible regex patterns for the id (logical OR!)
id_patterns = [
id_patterns = [
"
[A-z0-9]{24}
"
,
"
^
[A-z0-9]{24}
$
"
,
"
[A-Z0-9]{6,8}
"
,
"
^
[A-Z0-9]{6,8}
$
"
,
]
]
# minimum and maximum lengths for the received strings
# minimum and maximum lengths for the received strings
...
@@ -192,7 +192,11 @@ def id_pattern_check(visitor_id: str) -> bool:
...
@@ -192,7 +192,11 @@ def id_pattern_check(visitor_id: str) -> bool:
Returns True if any of the patterns from the config matches.
Returns True if any of the patterns from the config matches.
Returns False if none of the patterns 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
:
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:
...
@@ -210,9 +214,12 @@ def length_check(data: dict, key: str, minimum: int, maximum: int) -> bool:
return
True
return
True
# This gets run for each request
@app.route
(
'
/
'
,
methods
=
[
'
POST
'
])
@app.route
(
'
/
'
,
methods
=
[
'
POST
'
])
def
post
():
def
post
():
"""
This function runs when a POST request on / is received
"""
if
not
request
.
data
:
if
not
request
.
data
:
# Missing data body, reject
# Missing data body, reject
app
.
logger
.
info
(
'
400, Missing data body
'
)
app
.
logger
.
info
(
'
400, Missing data body
'
)
...
@@ -240,6 +247,10 @@ def post():
...
@@ -240,6 +247,10 @@ def post():
# This gets run for each request
# This gets run for each request
@app.route
(
'
/
'
,
methods
=
[
'
GET
'
])
@app.route
(
'
/
'
,
methods
=
[
'
GET
'
])
def
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
"
]:
if
config
[
"
application
"
][
"
ignore_get_requests
"
]:
app
.
logger
.
info
(
'
501, Get Request Ignored
'
)
app
.
logger
.
info
(
'
501, Get Request Ignored
'
)
return
""
,
501
return
""
,
501
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment