From 9de94414d084624b1376f6ade8b97d2aa310cb30 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 27 Feb 2020 23:07:23 +0000 Subject: [PATCH] Authenticate with portal to get list of cards --- .gitignore | 1 + main.py | 6 +++++- secrets.py.example | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 secrets.py.example diff --git a/.gitignore b/.gitignore index a5bb183..036cdf8 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,4 @@ ENV/ *.swo card_data.json +secrets.py diff --git a/main.py b/main.py index 8a83cd8..34d2b99 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,8 @@ import serial import time from signal import * +import secrets + DEBUG = os.environ.get('DEBUG', False) RELAY_PIN = 17 @@ -127,11 +129,13 @@ def update_thread(card_data_queue): logging.info('Cards changed, pulling update from API') try: - res = requests.get(API_DOOR, timeout=5) + headers = {'Authorization': 'Bearer ' + secrets.DOOR_API_KEY} + res = requests.get(API_DOOR, headers=headers, timeout=5) res.raise_for_status() res = res.json() except BaseException as e: logging.error('Problem GETting door: {} - {}'.format(e.__class__.__name__, str(e))) + last_card_change = None continue logging.info('Got {} cards from API'.format(str(len(res)))) diff --git a/secrets.py.example b/secrets.py.example new file mode 100644 index 0000000..d737ac5 --- /dev/null +++ b/secrets.py.example @@ -0,0 +1,3 @@ +# Door cards API key +# should be equal to the auth token value set in Spaceport +DOOR_API_KEY = ''