Files
firestar5683 a82935f326 User interfaces and Android Auto
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: pharmacomaniac <blittle65@gmail.com>

Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

39 lines
1.2 KiB
Python

"""Authentication for the existing statistics service."""
import os
from pathlib import Path
import stat
CLIENT_TOKEN = 'StarPilot'
TOKEN_FILE = Path('/data/starpilot/analytics/token')
def _token(value):
if not isinstance(value, str):
return None
value = value.strip()
return value if 16 <= len(value) <= 4096 and all(33 <= ord(c) <= 126 for c in value) else None
def read_token():
value = os.environ.get('STARPILOT_STATS_TOKEN')
if value is not None:
return _token(value)
explicit_path = os.environ.get('STARPILOT_STATS_TOKEN_FILE')
path = Path(explicit_path) if explicit_path is not None else TOKEN_FILE
descriptor = None
try:
descriptor = os.open(path, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK)
info = os.fstat(descriptor)
if (not stat.S_ISREG(info.st_mode) or info.st_mode & 0o077 or
info.st_uid not in (0, os.getuid()) or not 16 <= info.st_size <= 4097):
return None
return _token(os.read(descriptor, 4097).decode('ascii'))
except FileNotFoundError:
return CLIENT_TOKEN if explicit_path is None else None
except (OSError, UnicodeError):
return None
finally:
if descriptor is not None:
os.close(descriptor)