1
0
Fork 0
Browse Source

add secirity token checks to status change A.P.I. call.

stable
Craig Oates 4 years ago
parent
commit
d377ef4eca
  1. BIN
      app/readings.db
  2. 32
      app/services/post_services.py
  3. 6
      app/swagger.yml

BIN
app/readings.db

Binary file not shown.

32
app/services/post_services.py

@ -30,21 +30,23 @@ def add_latest_reading(meter, info):
return make_response("Meter Id. not recognised. Must be between 1 and 3.", 400)
return make_response("Invalid token.", 400)
def log_status_change(device, status):
# NEED TO ADD TOKEN.
if device == 1:
return add_status_change_to_device1(status)
elif device == 2:
return add_status_change_to_device2(status)
elif device == 3:
return add_status_change_to_device3(status)
elif device == 4:
return add_status_change_to_device4(status)
elif device == 5:
return add_status_change_to_device5(status)
elif device == 6:
return add_status_change_to_device6(status)
return make_response("Device Id. not recognised. Must be between 1 and 6.", 400)
def log_status_change(device, info):
if info["token"] == device_check_token:
status = {"time":info["time"], "status":info["status"]}
if device == 1:
return add_status_change_to_device1(status)
elif device == 2:
return add_status_change_to_device2(status)
elif device == 3:
return add_status_change_to_device3(status)
elif device == 4:
return add_status_change_to_device4(status)
elif device == 5:
return add_status_change_to_device5(status)
elif device == 6:
return add_status_change_to_device6(status)
return make_response("Device Id. not recognised. Must be between 1 and 6.", 400)
return make_response("Invalid token.", 400)
'''
Nitty-Gritty Functions

6
app/swagger.yml

@ -255,6 +255,12 @@ paths:
description: >-
The current status of the device you would like to log.
The two status types are "on" and "off".
token:
type: string
example: it-is-not-password-if-you-are-wondering
description: >-
This is basically a token to check the info. sent to
the server is from a valid machine.
responses:
201:
description: >-