Files
dragonpilot/tools/lib/auth_config.py
Dragonpilot Team 32da3d10c7 dragonpilot v2022.08.14
version: dragonpilot v0.8.16 release
date: 2022-08-14T16:03:36
dp-dev(priv) master commit: 9a40536565e6da64122ef8c30d7e97523fde518e
2022-08-14 16:03:47 -07:00

35 lines
653 B
Python

import json
import os
from common.file_helpers import mkdirs_exists_ok
from system.hardware import PC
class MissingAuthConfigError(Exception):
pass
if PC:
CONFIG_DIR = os.path.expanduser('~/.comma')
else:
CONFIG_DIR = "/tmp/.comma"
mkdirs_exists_ok(CONFIG_DIR)
def get_token():
try:
with open(os.path.join(CONFIG_DIR, 'auth.json')) as f:
auth = json.load(f)
return auth['access_token']
except Exception:
return None
def set_token(token):
with open(os.path.join(CONFIG_DIR, 'auth.json'), 'w') as f:
json.dump({'access_token': token}, f)
def clear_token():
os.unlink(os.path.join(CONFIG_DIR, 'auth.json'))