Authenticate with portal to get list of cards

This commit is contained in:
Tanner Collin 2020-02-27 23:07:23 +00:00
parent cbb5a360b9
commit 9de94414d0
3 changed files with 9 additions and 1 deletions

1
.gitignore vendored
View File

@ -103,3 +103,4 @@ ENV/
*.swo
card_data.json
secrets.py

View File

@ -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))))

3
secrets.py.example Normal file
View File

@ -0,0 +1,3 @@
# Door cards API key
# should be equal to the auth token value set in Spaceport
DOOR_API_KEY = ''