Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
StorageLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ProjectLeaf
StorageLeaf
Commits
0c281d0c
Commit
0c281d0c
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
Fixed #4 - api key authentication
parent
3bed664a
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
docs/api.yml
+7
-0
7 additions, 0 deletions
docs/api.yml
settings-example.json
+2
-1
2 additions, 1 deletion
settings-example.json
src/blueprints/Routes.py
+2
-0
2 additions, 0 deletions
src/blueprints/Routes.py
src/logic/AuthenticationWrapper.py
+22
-0
22 additions, 0 deletions
src/logic/AuthenticationWrapper.py
with
33 additions
and
1 deletion
docs/api.yml
+
7
−
0
View file @
0c281d0c
...
...
@@ -139,6 +139,13 @@ paths:
post
:
summary
:
Adds a new measurement. Non-existent device or sensor will be created automatically.
operationId
:
addMeasurement
parameters
:
-
in
:
header
name
:
apiKey
description
:
The api key
required
:
true
schema
:
type
:
string
requestBody
:
description
:
Measurement to add
required
:
true
...
...
This diff is collapsed.
Click to expand it.
settings-example.json
+
2
−
1
View file @
0c281d0c
...
...
@@ -11,6 +11,7 @@
"databasePath"
:
"storageLeaf.db"
},
"api"
:
{
"url"
:
"http://localhost:10003"
"url"
:
"http://localhost:10003"
,
"key"
:
""
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/blueprints/Routes.py
+
2
−
0
View file @
0c281d0c
...
...
@@ -7,6 +7,7 @@ import yaml
from
flask
import
Blueprint
,
request
,
jsonify
,
render_template
from
logic
import
Constants
from
logic.AuthenticationWrapper
import
require_api_key
from
logic.Database
import
Database
from
logic.RequestValidator
import
ValidationError
,
RequestValidator
...
...
@@ -96,6 +97,7 @@ def construct_blueprint(settings, version):
return
jsonify
(
database
.
get_all_measurements_for_sensor
(
sensorID
))
@routes.route
(
'
/measurements
'
,
methods
=
[
'
POST
'
])
@require_api_key
(
password
=
settings
[
'
api
'
][
'
key
'
])
def
addMeasurement
():
try
:
parameters
=
RequestValidator
.
validate
(
request
,
DeviceParameters
.
get_values
())
...
...
This diff is collapsed.
Click to expand it.
src/logic/AuthenticationWrapper.py
0 → 100644
+
22
−
0
View file @
0c281d0c
from
functools
import
wraps
from
flask
import
request
,
jsonify
def
require_api_key
(
password
):
def
wrap_route
(
func
):
@wraps
(
func
)
def
check_api_key
(
*
args
,
**
kwargs
):
apiKey
=
request
.
headers
.
get
(
'
apiKey
'
)
if
not
apiKey
:
return
jsonify
({
'
message
'
:
'
apiKey missing
'
}),
401
if
apiKey
==
password
:
# redirect to requested url
return
func
(
*
args
,
**
kwargs
)
return
jsonify
({
'
message
'
:
'
apiKey invalid
'
}),
401
return
check_api_key
return
wrap_route
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