Skip to content
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

feat: add the ability to store API key in a secure maner #158

Merged
merged 11 commits into from
Aug 25, 2024
Merged

Conversation

clementb49
Copy link
Collaborator

@clementb49 clementb49 commented Aug 17, 2024

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new API key storage management feature, allowing users to select how their API keys are stored (plain or secure).
    • Added a user interface component to manage the API key storage method within the account dialog.
  • Bug Fixes

    • Enhanced error handling during account creation to capture more exceptions.
  • Chores

    • Updated project dependencies to include the keyring package for improved secure credential storage.

Copy link
Contributor

coderabbitai bot commented Aug 17, 2024

Walkthrough

The recent changes introduce an enumeration for key storage methods in the Account class, enabling secure handling of API keys with optional integration of a keyring service. The account management GUI has been updated to allow users to select their preferred storage method, enhancing user interaction with new interface elements and validation checks. Additionally, the pyproject.toml file has been modified to include the keyring package as a dependency for secure credential management.

Changes

Files Change Summary
basilisk/account.py, basilisk/gui/account_dialog.py Introduced KeyStorageMethodEnum for API key storage methods. Updated the Account class for keyring integration and enhanced the account dialog UI for storage method selection and validation.
pyproject.toml Added keyring as a dependency for secure credential storage and updated package configurations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AccountDialog
    participant Account
    participant KeyringService

    User->>AccountDialog: Open account dialog
    AccountDialog->>Account: Load account data
    Account->>AccountDialog: Return current API key storage method
    AccountDialog->>User: Display storage method options
    User->>AccountDialog: Select storage method
    AccountDialog->>Account: Save selected method
    AccountDialog->>KeyringService: Store API key if system method selected
    KeyringService-->>Account: API key securely stored
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 62e8804 and 82437eb.

Files selected for processing (2)
  • basilisk/account.py (9 hunks)
  • basilisk/gui/account_dialog.py (16 hunks)
Additional comments not posted (6)
basilisk/account.py (3)

54-73: Approved changes in validate_key method.

The implementation correctly differentiates between "plain" and "system" methods. Ensure that the keyring integration is tested thoroughly to prevent runtime errors.

Consider adding unit tests for this method to ensure it behaves as expected under various scenarios, including edge cases where the key might not be found in the keyring.


76-82: Approved changes in dump_secret method.

The method now supports saving the key to the keyring when the storage method is "system". This change is a significant improvement in security by avoiding plaintext storage.

However, ensure that all usages of dump_secret handle the None return value appropriately to avoid NoneType errors.


84-86: Approved addition of delete_keyring_password method.

This new method securely removes stored passwords from the keyring when an account is deleted, ensuring sensitive information is properly managed and disposed of.

basilisk/gui/account_dialog.py (3)

97-99: Approved changes in init_data method.

The updates ensure that the combo box reflects the current storage method associated with the account being edited.

Consider adding a default or placeholder entry in the key_storage_methods to ensure clarity for the user.


119-123: Approved changes in on_ok method.

Significant changes are made to include validation checks to ensure users select a key storage method before proceeding. The chosen storage method is saved alongside the API key when the dialog is confirmed, ensuring that the account's configuration is accurately updated.

Also applies to: 129-131, 134-140


326-332: Approved changes in on_org_list_key_down method.

The updates enhance user interaction by allowing quick actions through keyboard shortcuts, such as editing and removing organizations directly from the list.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot changed the title @coderabbitai Enhance Account Class with API Key Storage Methods and GUI Updates Aug 17, 2024
@clementb49 clementb49 changed the title Enhance Account Class with API Key Storage Methods and GUI Updates feat: add the ability to store API key in a secure maner Aug 17, 2024
@clementb49 clementb49 added this to the v0.1a5 milestone Aug 17, 2024
@clementb49
Copy link
Collaborator Author

@coderabbitai full review

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Comment on lines 108 to 112
def __init__(self, **data):
try:
super().__init__(**data)
except ValidationError as e:
log.error(
f"Error in account {e} the account will not be accessible"
)
except Exception as e:
log.error(f"Error creating account: {e}", exc_info=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Lack of Documentation for Error Handling in the Account Constructor

The __init__ method in basilisk/account.py lacks comments or documentation explaining the broad exception handling strategy. This absence could lead to masking other unexpected issues. Consider adding documentation to clarify the rationale behind this approach.

  • basilisk/account.py: Lines 108-112
Analysis chain

Enhanced error handling in the Account constructor.

The constructor now catches all exceptions, logs them, and rethrows. This is good for debugging but ensure that this broad exception handling does not mask other unexpected issues.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if detailed error handling is documented.
# Test: Search for comments regarding error handling in the Account constructor.
rg --type python -A 5 $'def __init__'

Length of output: 69


Script:

#!/bin/bash
# Description: Verify if detailed error handling is documented.
# Test: Search for comments regarding error handling in the Account constructor.
rg --type py -A 5 $'def __init__'

Length of output: 9376

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

@clementb49
Copy link
Collaborator Author

@coderabbitai summary

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Comment on lines +97 to +99
if not self.organization:
self.key_storage_method.SetSelection(0)
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling the default selection more robustly.

When no organization is present, the default selection is set to 0. Consider adding a default or placeholder entry in the key_storage_methods to ensure clarity for the user.

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