Skip to content

Support fetching tokens from an external command#469

Draft
ammachado wants to merge 5 commits into
psss:mainfrom
ammachado:did-pwmgr
Draft

Support fetching tokens from an external command#469
ammachado wants to merge 5 commits into
psss:mainfrom
ammachado:did-pwmgr

Conversation

@ammachado
Copy link
Copy Markdown
Contributor

Summary

  • Add token_command as a third token source alongside token / token_file, so plugins can pull secrets from password managers such as BitWarden (bw get password did-jira) or 1Password (op read op://Personal/Jira/token). The command is parsed with shlex (no shell) and its stripped stdout is used as the token; failures raise ConfigError. Results are memoized per process via functools.lru_cache so multiple config sections sharing a command only invoke the external tool once.
  • Breaking change: setting more than one of token, token_file, token_command in a section is now a hard ConfigError. Previously the lower-precedence keys were silently ignored.
  • Updated the jira and confluence plugin docstrings to document token_command and the mutual-exclusion rule. Other plugins automatically gain the feature through the shared did.base.get_token helper.
  • Added a CLAUDE.md with repo guidance (Makefile commands, three-layer architecture, plugin conventions, unit vs. FMF tests).

Test plan

  • pytest tests/unit/test_base.py::TestGetToken — 13/13 passing (5 new tests for the command source, mutual exclusion, failure modes, and memoization)
  • Full pytest tests/unit -n auto clean except for pre-existing failures unrelated to token handling (nitrate/psycopg2 build needs pg_config locally; one redmine live-data test)
  • CI runs the full suite with .[all] installed
  • Manual smoke: configure a plugin with token_command = printf %s ... and confirm the report runs

🤖 Generated with Claude Code

ammachado and others added 5 commits May 15, 2026 16:54
Documents the Makefile-driven test/lint/RPM workflow, the
CLI/config → Stats → plugins architecture, how to add a new
plugin, and the unit vs. FMF/tmt test split.

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
Add `token_command` as a third token source alongside `token` and
`token_file`, so secrets can be pulled from password managers such as
BitWarden (`bw get password ...`) or 1Password (`op read op://...`).
The command is parsed with shlex (no shell) and its stdout is used as
the token; failures raise `ConfigError`. Results are memoized per
process so multiple sections sharing a command only invoke the tool
once.

Setting more than one of `token`, `token_file`, `token_command` is now
a hard `ConfigError` (previously the lower-precedence keys were
silently ignored).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
Restore the original silent-precedence behavior when more than one of
`token`, `token_file`, `token_command` is set: `token` wins, then
`token_file`, then `token_command`. Keeps the new `token_command`
source and its memoization, but avoids breaking configs that happen
to set multiple keys.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
The test setUp reaches into `did.base._run_token_command.cache_clear`
to reset memoization between tests; that is intentional access to an
internal helper, so disable the warning on that line.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
Project flake8 config sets `max-doc-length = 72`. Reflow the new
`_run_token_command` and `get_token` docstrings plus a few test
docstrings to fit the limit; no behavior change.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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