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("Meter Id. not recognised. Must be between 1 and 3.", 400)
return make_response("Invalid token.", 400) return make_response("Invalid token.", 400)
def log_status_change(device, status): def log_status_change(device, info):
# NEED TO ADD TOKEN. if info["token"] == device_check_token:
if device == 1: status = {"time":info["time"], "status":info["status"]}
return add_status_change_to_device1(status) if device == 1:
elif device == 2: return add_status_change_to_device1(status)
return add_status_change_to_device2(status) elif device == 2:
elif device == 3: return add_status_change_to_device2(status)
return add_status_change_to_device3(status) elif device == 3:
elif device == 4: return add_status_change_to_device3(status)
return add_status_change_to_device4(status) elif device == 4:
elif device == 5: return add_status_change_to_device4(status)
return add_status_change_to_device5(status) elif device == 5:
elif device == 6: return add_status_change_to_device5(status)
return add_status_change_to_device6(status) elif device == 6:
return make_response("Device Id. not recognised. Must be between 1 and 6.", 400) 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 Nitty-Gritty Functions

6
app/swagger.yml

@ -255,6 +255,12 @@ paths:
description: >- description: >-
The current status of the device you would like to log. The current status of the device you would like to log.
The two status types are "on" and "off". 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: responses:
201: 201:
description: >- description: >-