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
f6578555
Commit
f6578555
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
cleanup old device and sensor routes
parent
b468fb2a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/StorageLeaf.py
+1
-3
1 addition, 3 deletions
src/StorageLeaf.py
src/blueprints/Devices.py
+0
-69
0 additions, 69 deletions
src/blueprints/Devices.py
src/blueprints/Routes.py
+0
-27
0 additions, 27 deletions
src/blueprints/Routes.py
src/blueprints/Sensors.py
+0
-52
0 additions, 52 deletions
src/blueprints/Sensors.py
with
1 addition
and
151 deletions
src/StorageLeaf.py
+
1
−
3
View file @
f6578555
...
@@ -3,7 +3,7 @@ import os
...
@@ -3,7 +3,7 @@ import os
from
TheCodeLabs_BaseUtils.DefaultLogger
import
DefaultLogger
from
TheCodeLabs_BaseUtils.DefaultLogger
import
DefaultLogger
from
TheCodeLabs_FlaskUtils.FlaskBaseApp
import
FlaskBaseApp
from
TheCodeLabs_FlaskUtils.FlaskBaseApp
import
FlaskBaseApp
from
blueprints
import
Routes
,
Devices
,
Sensors
,
Measurements
from
blueprints
import
Sensors
,
Measurements
from
logic
import
Constants
from
logic
import
Constants
from
logic.BackupService
import
BackupService
from
logic.BackupService
import
BackupService
from
logic.DiscoveryService
import
DiscoveryService
from
logic.DiscoveryService
import
DiscoveryService
...
@@ -23,8 +23,6 @@ class StorageLeaf(FlaskBaseApp):
...
@@ -23,8 +23,6 @@ class StorageLeaf(FlaskBaseApp):
self
.
_discoveryService
.
start
()
self
.
_discoveryService
.
start
()
def
_register_blueprints
(
self
,
app
):
def
_register_blueprints
(
self
,
app
):
app
.
register_blueprint
(
Routes
.
construct_blueprint
(
self
.
_settings
,
self
.
_version
))
app
.
register_blueprint
(
Devices
.
construct_blueprint
(
self
.
_settings
,
self
.
_backupService
))
app
.
register_blueprint
(
Sensors
.
construct_blueprint
(
self
.
_settings
,
self
.
_backupService
))
app
.
register_blueprint
(
Sensors
.
construct_blueprint
(
self
.
_settings
,
self
.
_backupService
))
app
.
register_blueprint
(
Measurements
.
construct_blueprint
(
self
.
_settings
,
self
.
_backupService
))
app
.
register_blueprint
(
Measurements
.
construct_blueprint
(
self
.
_settings
,
self
.
_backupService
))
return
app
return
app
...
...
This diff is collapsed.
Click to expand it.
src/blueprints/Devices.py
deleted
100644 → 0
+
0
−
69
View file @
b468fb2a
from
typing
import
Dict
from
flask
import
Blueprint
,
jsonify
,
request
from
logic.AuthenticationWrapper
import
require_api_key
from
logic.BackupService
import
BackupService
from
logic.Parameters
import
DeviceParameters
from
logic.RequestValidator
import
RequestValidator
,
ValidationError
from
logic.database.Database
import
Database
def
construct_blueprint
(
settings
:
Dict
,
backupService
:
BackupService
):
devices
=
Blueprint
(
'
devices
'
,
__name__
)
@devices.route
(
'
/devices
'
,
methods
=
[
'
GET
'
])
def
get_all_devices
():
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
return
jsonify
(
database
.
deviceAccess
.
get_all_devices
())
@devices.route
(
'
/device/<int:deviceID>
'
,
methods
=
[
'
GET
'
])
def
get_device
(
deviceID
):
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
return
jsonify
(
database
.
deviceAccess
.
get_device
(
deviceID
))
@devices.route
(
'
/device/<int:deviceID>/sensors/
'
,
methods
=
[
'
GET
'
])
def
get_all_sensors_for_device
(
deviceID
):
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
device
=
database
.
deviceAccess
.
get_device
(
deviceID
)
if
not
device
:
return
jsonify
({
'
success
'
:
False
,
'
msg
'
:
f
'
No device with id
"
{
deviceID
}
"
existing
'
})
return
jsonify
(
database
.
sensorAccess
.
get_all_sensors_for_device
(
deviceID
))
@devices.route
(
'
/device/<int:deviceID>
'
,
methods
=
[
'
DELETE
'
])
@require_api_key
(
password
=
settings
[
'
api
'
][
'
key
'
])
def
delete_device
(
deviceID
):
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
if
not
database
.
deviceAccess
.
get_device
(
deviceID
):
return
jsonify
({
'
success
'
:
False
,
'
msg
'
:
f
'
No device with id
"
{
deviceID
}
"
existing
'
})
sensors
=
database
.
sensorAccess
.
get_all_sensors_for_device
(
deviceID
)
for
sensor
in
sensors
:
database
.
measurementAccess
.
delete_measurements_for_sensor
(
sensor
[
'
id
'
])
database
.
sensorAccess
.
delete_sensor
(
sensor
[
'
id
'
])
database
.
deviceAccess
.
delete_device
(
deviceID
)
return
jsonify
({
'
success
'
:
True
})
@devices.route
(
'
/device
'
,
methods
=
[
'
POST
'
])
@require_api_key
(
password
=
settings
[
'
api
'
][
'
key
'
])
def
add_device
():
try
:
parameters
=
RequestValidator
.
validate
(
request
,
[
DeviceParameters
.
DEVICE
.
value
])
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
deviceName
=
parameters
[
DeviceParameters
.
DEVICE
.
value
]
existingDevice
=
database
.
deviceAccess
.
get_device_by_name
(
deviceName
)
if
existingDevice
:
return
jsonify
({
'
success
'
:
False
,
'
msg
'
:
f
'
A device called
"
{
deviceName
}
"
already exists (ID:
{
existingDevice
[
"
id
"
]
}
)
'
})
database
.
deviceAccess
.
add_device
(
deviceName
)
except
ValidationError
as
e
:
return
e
.
response
,
400
return
jsonify
({
'
success
'
:
True
})
return
devices
This diff is collapsed.
Click to expand it.
src/blueprints/Routes.py
deleted
100644 → 0
+
0
−
27
View file @
b468fb2a
import
json
import
os
import
yaml
from
flask
import
Blueprint
,
render_template
from
logic
import
Constants
def
construct_blueprint
(
settings
,
version
):
routes
=
Blueprint
(
'
routes
'
,
__name__
)
@routes.route
(
'
/
'
,
methods
=
[
'
GET
'
])
def
index
():
yamlPath
=
os
.
path
.
join
(
Constants
.
ROOT_DIR
,
'
docs
'
,
'
api.yml
'
)
with
open
(
yamlPath
,
'
r
'
)
as
yamlFile
:
specification
=
yaml
.
load
(
yamlFile
,
Loader
=
yaml
.
FullLoader
)
specification
[
'
servers
'
][
0
][
'
url
'
]
=
settings
[
'
api
'
][
'
url
'
]
specification
[
'
info
'
][
'
version
'
]
=
version
[
'
name
'
]
specification
=
json
.
dumps
(
specification
)
return
render_template
(
'
api.html
'
,
appName
=
Constants
.
APP_NAME
,
openApiSpecification
=
specification
)
return
routes
This diff is collapsed.
Click to expand it.
src/blueprints/Sensors.py
+
0
−
52
View file @
f6578555
...
@@ -2,26 +2,13 @@ from typing import Dict
...
@@ -2,26 +2,13 @@ from typing import Dict
from
flask
import
Blueprint
,
jsonify
,
request
from
flask
import
Blueprint
,
jsonify
,
request
from
logic.AuthenticationWrapper
import
require_api_key
from
logic.BackupService
import
BackupService
from
logic.BackupService
import
BackupService
from
logic.Parameters
import
SensorParameters
from
logic.RequestValidator
import
RequestValidator
,
ValidationError
from
logic.database.Database
import
Database
from
logic.database.Database
import
Database
def
construct_blueprint
(
settings
:
Dict
,
backupService
:
BackupService
):
def
construct_blueprint
(
settings
:
Dict
,
backupService
:
BackupService
):
sensors
=
Blueprint
(
'
sensors
'
,
__name__
)
sensors
=
Blueprint
(
'
sensors
'
,
__name__
)
@sensors.route
(
'
/sensors
'
,
methods
=
[
'
GET
'
])
def
get_all_sensors
():
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
return
jsonify
(
database
.
sensorAccess
.
get_all_sensors
())
@sensors.route
(
'
/sensor/<int:sensorID>
'
,
methods
=
[
'
GET
'
])
def
get_sensor
(
sensorID
):
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
return
jsonify
(
database
.
sensorAccess
.
get_sensor
(
sensorID
))
@sensors.route
(
'
/sensor/<int:sensorID>/measurements
'
,
methods
=
[
'
GET
'
])
@sensors.route
(
'
/sensor/<int:sensorID>/measurements
'
,
methods
=
[
'
GET
'
])
def
get_all_measurements_for_sensor_with_limit
(
sensorID
:
int
):
def
get_all_measurements_for_sensor_with_limit
(
sensorID
:
int
):
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
...
@@ -44,43 +31,4 @@ def construct_blueprint(settings: Dict, backupService: BackupService):
...
@@ -44,43 +31,4 @@ def construct_blueprint(settings: Dict, backupService: BackupService):
return
jsonify
(
database
.
measurementAccess
.
get_latest_measurements_for_sensor
(
sensorID
))
return
jsonify
(
database
.
measurementAccess
.
get_latest_measurements_for_sensor
(
sensorID
))
@sensors.route
(
'
/sensor/<int:sensorID>
'
,
methods
=
[
'
DELETE
'
])
@require_api_key
(
password
=
settings
[
'
api
'
][
'
key
'
])
def
delete_sensor
(
sensorID
):
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
if
not
database
.
sensorAccess
.
get_sensor
(
sensorID
):
return
jsonify
({
'
success
'
:
False
,
'
msg
'
:
f
'
No sensor with id
"
{
sensorID
}
"
existing
'
})
database
.
measurementAccess
.
delete_measurements_for_sensor
(
sensorID
)
database
.
sensorAccess
.
delete_sensor
(
sensorID
)
return
jsonify
({
'
success
'
:
True
})
@sensors.route
(
'
/sensor
'
,
methods
=
[
'
POST
'
])
@require_api_key
(
password
=
settings
[
'
api
'
][
'
key
'
])
def
add_sensor
():
try
:
parameters
=
RequestValidator
.
validate
(
request
,
[
SensorParameters
.
NAME
.
value
,
SensorParameters
.
TYPE
.
value
,
SensorParameters
.
DEVICE_ID
.
value
])
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
],
backupService
)
deviceID
=
parameters
[
SensorParameters
.
DEVICE_ID
.
value
]
sensorName
=
parameters
[
SensorParameters
.
NAME
.
value
]
sensorType
=
parameters
[
SensorParameters
.
TYPE
.
value
]
device
=
database
.
deviceAccess
.
get_device
(
deviceID
)
if
not
device
:
return
jsonify
({
'
success
'
:
False
,
'
msg
'
:
f
'
No device with id
"
{
deviceID
}
"
existing
'
})
existingSensor
=
database
.
sensorAccess
.
get_sensor_by_name_and_device_id
(
deviceID
,
sensorName
)
if
existingSensor
:
return
jsonify
({
'
success
'
:
False
,
'
msg
'
:
f
'
A sensor called
"
{
sensorName
}
"
already exists (ID:
{
existingSensor
[
"
id
"
]
}
) for device
{
deviceID
}
'
})
database
.
sensorAccess
.
add_sensor
(
deviceID
,
sensorName
,
sensorType
)
except
ValidationError
as
e
:
return
e
.
response
,
400
return
jsonify
({
'
success
'
:
True
})
return
sensors
return
sensors
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