Skip to main content

Module admin_cli

Module admin_cli 

Source
Expand description

ai-crew-sync admin … from the operator’s own machine.

Talks to /admin/* with an administrative credential stored by admin login, verifies every token it mints by presenting it to /mcp and checking whoami answers with the agent and team that were asked for, and can write the result straight into the per-team token file.

Every function takes the configuration directory explicitly so the integration tests run the real flow against a temporary directory; the binary resolves it once with config_dir.

Secrets: the credential is read from a hidden prompt or stdin, never from an argument; a minted token is printed exactly once, or not at all when it is saved to a file. Nothing here logs.

Structs§

AdminConfig
Endpoint and credential of a logged-in administrator.
Api
A logged-in client for /admin/*.
Issued
What /admin minted: the secret plus the identity the server says it has.
SaveTarget
Where a saved token goes: tokens-<team> in the config directory, as the line <repo>=<token>.

Constants§

CONFIG_FILE
Name of the file holding the endpoint and credential inside the configuration directory.

Functions§

config_dir
Where admin login keeps its state and --save writes token files. BUS_CONFIG_DIR, else $XDG_CONFIG_HOME/ai-crew-sync, else $HOME/.config/ai-crew-sync.
finish_issue
Everything after the mint: verify the token on /mcp as exactly the requested agent and team, then either save it (and say nothing of the secret) or print it once. On a mismatch the token is revoked, nothing is written, and the error says what the server answered.
load_config
Load the stored configuration. BUS_ADMIN_URL and BUS_ADMIN_TOKEN override the file, for scripts and CI that never run admin login.
login
Verify the credential against the bus and, only then, persist it. Returns the scope the server reported.
normalize_base_url
https://host:8443, https://host:8443/, https://host:8443/mcp and https://host:8443/admin all mean the same bus.
read_credential
Read the credential without it touching argv or shell history: from stdin when asked, else from a hidden prompt.
remove_config
save_config
tokens_file
upsert_token_entry
Set <name>=<token> in the file, keeping every other line as it is: comments, blank lines, order, and above all _base. A duplicate of name left by a hand edit collapses to the one updated line. Atomic and 0600, and nothing else in the file is touched — a previous token for the same name is replaced in the file but never revoked on the bus.
validate_repo_name
--repo names a line in a file people edit by hand: one word, no =, no whitespace, and never a path.
whoami_on_mcp
Present a freshly minted token to /mcp and return the agent and team it authenticates as. This is the server’s word, not the request’s.
write_private
Write content to path atomically (temp file + rename) with mode 0600. A crash mid-write leaves the previous file intact, never a truncated one.