1
0
Fork 0
Browse Source

add security token checks when adding new reading.

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

BIN
app/readings.db

Binary file not shown.

22
app/services/post_services.py

@ -16,16 +16,22 @@ you will need to head to the /get_services.py/ file. It should be in
the same directory as this: /services/. the same directory as this: /services/.
''' '''
def add_latest_reading(meter,reading): device_check_token = "QWERTYuiopasdfghjklzxcvbnm_1234567890"
if meter == 1:
return add_reading_to_meter1(reading) def add_latest_reading(meter, info):
elif meter == 2: if info["token"] == device_check_token:
return add_reading_to_meter2(reading) reading = {"reading":info["reading"], "time":info["time"]}
elif meter == 3: if meter == 1:
return add_reading_to_meter3(reading) return add_reading_to_meter1(reading)
return make_response("Meter Id. not recognised. Must be between 1 and 3.", 400) elif meter == 2:
return add_reading_to_meter2(reading)
elif meter == 3:
return add_reading_to_meter3(reading)
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): def log_status_change(device, status):
# NEED TO ADD TOKEN.
if device == 1: if device == 1:
return add_status_change_to_device1(status) return add_status_change_to_device1(status)
elif device == 2: elif device == 2:

6
app/swagger.yml

@ -69,6 +69,12 @@ paths:
This represents the amount of light the light meter This represents the amount of light the light meter
recorded. This is the most important piece of data recorded. This is the most important piece of data
you will post in this data-object. you will post in this data-object.
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: >-