feat: add credential store#15
Open
panasheMuriro wants to merge 5 commits into
Open
Conversation
panasheMuriro
commented
Jul 24, 2026
Collaborator
- Adds a CredentialStore abstraction for securely persisting the OpenRouter API key needed by the upcoming gitlance suggest command, avoiding repo files or CLI flags that risk leaking it via shell history or process listings.
- Provides two backends behind that abstraction — an OS keyring-backed store (Secret Service/Keychain/Credential Manager, primary) and a file-based fallback for headless environments without a keyring session — plus a CredentialStoreFactory that tries keyring first and falls back automatically, mirroring the pattern used by kfactory's credential_store.
There was a problem hiding this comment.
Pull request overview
Adds a CredentialStore abstraction to persist the OpenRouter API key securely, preferring OS keyring storage with a file-based fallback for environments without a working keyring session (e.g., headless CI).
Changes:
- Introduces
credential_storemodule withCredentialStoretrait, error type, and a factory for selecting an implementation. - Adds
KeyringCredentialStore(OS keyring viakeyring) andFileCredentialStore(plaintext token under$XDG_RUNTIME_DIR). - Updates dependencies to include
keyring(andrpassword) and refreshesCargo.lock.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib.rs | Exposes the new credential_store module from the crate. |
| src/credential_store/mod.rs | Defines the CredentialStore trait and re-exports store implementations/factory/error. |
| src/credential_store/error.rs | Adds CredentialStoreError for init/read/write/delete failures. |
| src/credential_store/factory.rs | Selects keyring-backed store first, with file fallback. |
| src/credential_store/keyring_store.rs | Implements keyring-backed token persistence with unit tests via a mock backend. |
| src/credential_store/file_store.rs | Implements $XDG_RUNTIME_DIR file-based token persistence with unit tests. |
| Cargo.toml | Adds dependencies for keyring support (and rpassword). |
| Cargo.lock | Locks new transitive dependencies introduced by keyring support. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
panasheMuriro
force-pushed
the
feat/credential-store
branch
from
July 24, 2026 09:12
7031792 to
811bedb
Compare
Needed for the credential-store module: keyring for OS-native secret storage. Signed-off-by: Panashe Muriro <panashemuriro2021@gmail.com>
Introduces the CredentialStore abstraction (get_name/read_token/write_token/delete_token) and its error type, ahead of adding concrete keyring- and file-backed implementations. Signed-off-by: Panashe Muriro <panashemuriro2021@gmail.com>
KeyringCredentialStore is the primary store, using the OS-native credential manager (Secret Service/Keychain/Credential Manager) via the keyring crate. Not covered by automated tests since it requires a real OS keyring session. Signed-off-by: Panashe Muriro <panashemuriro2021@gmail.com>
FileCredentialStore stores the token at $XDG_RUNTIME_DIR/gitlance/application_token with 0600 permissions on Unix, for headless environments without a usable OS keyring session. Signed-off-by: Panashe Muriro <panashemuriro2021@gmail.com>
CredentialStoreFactory::create_store() tries the keyring store first and falls back to the file store if the keyring is unavailable, returning a Box<dyn CredentialStore> so callers don't need to know which backend is in use. Signed-off-by: Panashe Muriro <panashemuriro2021@gmail.com>
panasheMuriro
force-pushed
the
feat/credential-store
branch
from
July 24, 2026 09:17
811bedb to
3355ef2
Compare
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.