Skip to content

Note when an exported key goes to a stored endpoint - #47

Merged
jon-trust merged 1 commit into
mainfrom
fix/saved-endpoint-warning
Oct 8, 2026
Merged

jon-trust merged 1 commit into
mainfrom
fix/saved-endpoint-warning

Conversation

@jon-trust

Copy link
Copy Markdown
Contributor

What

Commands now print a note on stderr when a key exported in TOC_API_KEY is about to be sent to a non-default endpoint that tmxcaliber init stored in the credentials file, and TOC_API_URL is unset:

Note: the key in TOC_API_KEY will be sent to <endpoint>, the endpoint stored in <credentials file>. Set TOC_API_URL to choose a different endpoint.

Why

The key and the endpoint are resolved independently, on purpose (see the comment in load_settings). So a key exported for one API, while init once stored a different endpoint, is sent to that stored endpoint with nothing on screen to say so. Resolution is unchanged; this only makes it visible.

How

  • Settings.endpoint_source records where the endpoint came from, and Settings.sends_environment_key_to_stored_endpoint owns the condition. The library still prints nothing.
  • remote_cli.connect() is the one place a client is built from resolved settings, and the one place the note is written. Every API command goes through it (run_api_command), and so does every ThreatModel reference given as a document source (resolve_command_source).
  • The note is printed once per run, before the first request, on stderr. Stdout is unchanged, so JSON output stays parseable.
  • A local file source still needs no key: connect is only called for a reference.
  • init is unchanged and keeps its own TOC_API_KEY note.

Version

0.5.4, since 0.5.3 shipped with #46.

Checks run locally

  • uv run coverage run ./test/run_tests.py: 578 passed
  • uv run ruff format --check ., uv run ruff check ., uv run mypy: clean
  • uv build and twine check: passed

The key and the endpoint are resolved independently, so a key exported
in TOC_API_KEY is sent to whatever non-default endpoint `tmxcaliber
init` stored, unless TOC_API_URL is also set. That precedence is
unchanged. Commands now print a note on stderr, once per run and before
the first request, naming the endpoint and the credentials file it came
from and pointing at TOC_API_URL. Stdout stays the command's output.

Settings records where the endpoint came from and owns the condition,
so the library still prints nothing. API commands and ThreatModel
references given as a document source both build their client through
remote_cli.connect, the one place the note is written.

Bump to 0.5.4.
@jon-trust
jon-trust merged commit fb142b7 into main Oct 8, 2026
4 checks passed
@jon-trust
jon-trust deleted the fix/saved-endpoint-warning branch October 8, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant