fix(plugins/bitwarden_item): point the locked-vault error at bw serve - #330
Merged
Merged
Conversation
The lookup and the module read the vault through the `bw serve` API on 127.0.0.1:8087, which keeps the session it was started with. Exporting BW_SESSION afterwards only reaches the `bw` CLI in the shell, so `bw status` reports "unlocked" while the API is still locked. The old message sent the admin to `bw login` and `bw unlock`, neither of which touches a running `bw serve`. Replace `is_unlocked` with `status`, which passes the raw value through, so the message can name what the API actually reported. The complete set of values is `unauthenticated`, `locked` and `unlocked`, verified against the StatusCommand of bw 2026.8.0. Both call sites share one message builder in the module_util so they cannot drift apart. Drop the trailing period from every raised message: AnsibleError appends ". <original message>" when it wraps an exception, so the period showed up doubled in the playbook output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The lookup and the module read the vault through the
bw serveAPI on127.0.0.1:8087. That daemon keeps the session it was started with, so exportingBW_SESSIONafterwards only reaches thebwCLI in the shell:The old message sent the admin to
bw loginandbw unlock, neither of which touches a runningbw serve, so the obvious next step was the wrong one.Change
is_unlockedis replaced bystatus, which passes the raw value through, so the message can name what the API actually reported. The complete set of values isunauthenticated,lockedandunlocked, verified against theStatusCommandof bw 2026.8.0:Both call sites share one message builder in the module_util so they cannot drift apart. What an admin sees now:
The same trap is now documented in the
requirementsof both DOCUMENTATION blocks and in the README section that shows thebw servesetup.Second, unrelated to the content: every raised message lost its trailing period.
AnsibleErrorappends". <original message>"when it wraps an exception (ansible/errors/__init__.py), so the period showed up doubled in the playbook output:Tests
New
TestStatusin the module_util tests covers the three status values, the message content (endpoint, status,bw serve) and the missing trailing period, with the reason in a comment. The lookup and module tests gained a settable vault status and one test each asserting thatunauthenticatedandlockedabort without creating anything.tox -e py313-ansible218: 135 passed.ruff,banditandvultureclean viapre-commit.