gate_tokens
gate_tokens
¶
Token CRUD for gate server per-task authentication.
Each task gets a prefixed random 128-bit hex token scoped to its project.
Tokens are stored in state_root()/gate/tokens.json and read by the
standalone gate server process (which receives the file path via
--token-file).
Token format: terok-g-<32 hex chars> (e.g. terok-g-a1b2c3…).
File format::
{"terok-g-<hex>": {"project": "<project_id>", "task": "<task_id>"}}
token_file_path(cfg=None)
¶
create_token(project_id, task_id, cfg=None)
¶
Generate a 128-bit hex token, persist atomically, and return it.
Uses secrets.token_hex(16) for cryptographic randomness.
Atomic write via tempfile + os.replace().
Source code in src/terok_sandbox/gate_tokens.py
revoke_token_for_task(project_id, task_id, cfg=None)
¶
Remove all tokens for the given project+task pair. Idempotent.