-
Notifications
You must be signed in to change notification settings - Fork 10
fix(cli): platform-specific keychain store hints after login (#235) #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adriannoes
wants to merge
2
commits into
dev
Choose a base branch
from
fix/cli-macos-keychain-hint-235
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
60 changes: 60 additions & 0 deletions
60
packages/cli/src/pipefy_cli/commands/_auth_keychain_hints.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """Platform-specific hints when OS keychain session storage fails after OAuth.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import platform | ||
|
|
||
| from pipefy_infra.config import config_dir | ||
|
|
||
| from pipefy_cli._docs import DOCS_CLI_AUTH_REF | ||
|
|
||
| _LINUX_HINT = ( | ||
| "On headless Linux, ensure a Secret Service daemon " | ||
| "(gnome-keyring, kwallet) is running, set " | ||
| "PIPEFY_KEYCHAIN_BACKEND=file to use a plaintext file backend, " | ||
| "or use a static PIPEFY_TOKEN." | ||
| ) | ||
|
|
||
| _MACOS_HINT = ( | ||
| "This is usually macOS denying the calling subprocess access to the " | ||
| "keychain ACL prompt (errSecParam, -25244). Run `pipefy auth login` once " | ||
| "from a regular Terminal.app session and click Always Allow when macOS " | ||
| "prompts; subsequent runs (including agent / IDE integrations) will write " | ||
| "without prompting." | ||
| ) | ||
|
|
||
| _WINDOWS_HINT = ( | ||
| "On Windows, Credential Manager may block writes from non-interactive " | ||
| "callers. Run `pipefy auth login` once from an interactive Command Prompt " | ||
| "or PowerShell window, or set PIPEFY_KEYCHAIN_BACKEND=file, or use a " | ||
| "static PIPEFY_TOKEN." | ||
| ) | ||
|
|
||
| _GENERIC_HINT = ( | ||
| f"Run `pipefy auth status` to inspect the active backend, or see " | ||
| f"{DOCS_CLI_AUTH_REF} for keychain troubleshooting." | ||
| ) | ||
|
|
||
|
|
||
| def keychain_store_failure_hint(*, backend: str) -> str: | ||
| """Return a remediation hint after ``store_session`` fails post-login.""" | ||
| if backend == "PlaintextKeyring": | ||
| return ( | ||
| f"Ensure the config directory is writable ({config_dir()}), " | ||
| "or use a static PIPEFY_TOKEN." | ||
| ) | ||
| return _keychain_hint_for_platform() | ||
|
|
||
|
|
||
| def _keychain_hint_for_platform() -> str: | ||
| system = platform.system() | ||
| if system == "Darwin": | ||
| return _MACOS_HINT | ||
| if system == "Linux": | ||
| return _LINUX_HINT | ||
| if system == "Windows": | ||
| return _WINDOWS_HINT | ||
| return _GENERIC_HINT | ||
|
|
||
|
|
||
| __all__ = ["keychain_store_failure_hint"] | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import platform | ||
|
|
||
| import pytest | ||
|
|
||
| from pipefy_cli.commands import _auth_keychain_hints as hints | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("system", "required", "forbidden"), | ||
| [ | ||
| ("Darwin", ["errSecParam", "Terminal.app", "Always Allow"], ["Secret Service"]), | ||
| ("Linux", ["Secret Service"], ["Terminal.app", "Credential Manager"]), | ||
| ("Windows", ["Credential Manager"], ["Secret Service", "Terminal.app"]), | ||
| ("FreeBSD", ["pipefy auth status"], []), | ||
| ], | ||
| ) | ||
| def test_keychain_hint_for_platform( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| system: str, | ||
| required: list[str], | ||
| forbidden: list[str], | ||
| ) -> None: | ||
| monkeypatch.setattr(platform, "system", lambda: system) | ||
| hint = hints.keychain_store_failure_hint(backend="Keyring") | ||
| for fragment in required: | ||
| assert fragment in hint | ||
| for fragment in forbidden: | ||
| assert fragment not in hint | ||
|
|
||
|
|
||
| def test_plaintext_backend_hint_ignores_platform( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ) -> None: | ||
| monkeypatch.setattr(platform, "system", lambda: "Darwin") | ||
| hint = hints.keychain_store_failure_hint(backend="PlaintextKeyring") | ||
| assert "config directory is writable" in hint | ||
| assert "errSecParam" not in hint |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.