mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-28 00:53:45 +08:00
33cfc2af03
(cherry picked from commit a47d1c56f60727cd5ad0056cb2479bad8c473c4d)
24 lines
563 B
Python
24 lines
563 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)
|