mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-18 10:23:43 +08:00
ebb202f29d
* tools: share cancellable browser sign-in * tools: invoke auth JSON mode directly from Cabana * tools: require an explicit Python module * tools: order module constants alphabetically * tools: use shared unauthorized handling for devices
31 lines
690 B
Python
31 lines
690 B
Python
import json
|
|
import os
|
|
from openpilot.common.hardware.hw import Paths
|
|
from openpilot.common.utils import atomic_write
|
|
|
|
|
|
class MissingAuthConfigError(Exception):
|
|
pass
|
|
|
|
|
|
def get_token():
|
|
try:
|
|
with open(os.path.join(Paths.config_root(), 'auth.json')) as f:
|
|
auth = json.load(f)
|
|
return auth['access_token']
|
|
except Exception:
|
|
return None
|
|
|
|
|
|
def set_token(token):
|
|
os.makedirs(Paths.config_root(), exist_ok=True)
|
|
with atomic_write(os.path.join(Paths.config_root(), 'auth.json'), overwrite=True) as f:
|
|
json.dump({'access_token': token}, f)
|
|
|
|
|
|
def clear_token():
|
|
try:
|
|
os.unlink(os.path.join(Paths.config_root(), 'auth.json'))
|
|
except FileNotFoundError:
|
|
pass
|