Skip to content

feat: add credential store#15

Open
panasheMuriro wants to merge 5 commits into
canonical:mainfrom
panasheMuriro:feat/credential-store
Open

feat: add credential store#15
panasheMuriro wants to merge 5 commits into
canonical:mainfrom
panasheMuriro:feat/credential-store

Conversation

@panasheMuriro

Copy link
Copy Markdown
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.

Copilot AI review requested due to automatic review settings July 24, 2026 08:14
@panasheMuriro panasheMuriro self-assigned this Jul 24, 2026
@panasheMuriro panasheMuriro changed the title Feat/credential store feat: add credential store Jul 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_store module with CredentialStore trait, error type, and a factory for selecting an implementation.
  • Adds KeyringCredentialStore (OS keyring via keyring) and FileCredentialStore (plaintext token under $XDG_RUNTIME_DIR).
  • Updates dependencies to include keyring (and rpassword) and refreshes Cargo.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.

Comment thread src/credential_store/file_store.rs Outdated
Comment thread src/credential_store/factory.rs
Comment thread Cargo.toml Outdated
@panasheMuriro
panasheMuriro force-pushed the feat/credential-store branch from 7031792 to 811bedb Compare July 24, 2026 09:12
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>
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.

2 participants