auth_config.py 623 B

1234567891011121314151617181920212223242526272829
  1. import json
  2. import os
  3. from openpilot.system.hardware.hw import Paths
  4. class MissingAuthConfigError(Exception):
  5. pass
  6. def get_token():
  7. try:
  8. with open(os.path.join(Paths.config_root(), 'auth.json')) as f:
  9. auth = json.load(f)
  10. return auth['access_token']
  11. except Exception:
  12. return None
  13. def set_token(token):
  14. os.makedirs(Paths.config_root(), exist_ok=True)
  15. with open(os.path.join(Paths.config_root(), 'auth.json'), 'w') as f:
  16. json.dump({'access_token': token}, f)
  17. def clear_token():
  18. try:
  19. os.unlink(os.path.join(Paths.config_root(), 'auth.json'))
  20. except FileNotFoundError:
  21. pass