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 auth refresh command #443

Merged
merged 8 commits into from
Aug 5, 2024
Merged

feat: add auth refresh command #443

merged 8 commits into from
Aug 5, 2024

Conversation

morgante
Copy link
Contributor

@morgante morgante commented Aug 5, 2024

Add grit auth refresh to explicitly refresh the auth token, and automatically refresh it when we need it for workflows.

Summary by CodeRabbit

  • New Features

    • Introduced a new command for refreshing authentication tokens, improving session management.
    • Added a refresh_token field to enhance the functionality of the authentication process.
  • Bug Fixes

    • Improved error messaging to guide users on refreshing expired tokens instead of logging in again.
  • Documentation

    • Enhanced logging for better clarity on token management.
  • Chores

    • Updated underlying functions to support the new authentication features and improve code readability.

@morgante morgante requested a review from a team as a code owner August 5, 2024 21:39
Copy link
Contributor

coderabbitai bot commented Aug 5, 2024

Walkthrough

Walkthrough

The recent changes enhance the authentication functionality across multiple components of the application. Key modifications include introducing a refresh token mechanism, updating the visibility of struct fields for better encapsulation, and refining error handling in authentication commands. These adjustments collectively improve the user experience by providing a more robust and maintainable authentication process.

Changes

Files Grouped Change Summary
crates/auth/src/auth0.rs, info.rs, testing.rs Modified AuthTokenResponseSuccess and AuthInfo structures to include a refresh token. Adjusted method return types for improved data encapsulation and added new async functions for token management.
crates/cli/src/commands/auth.rs, auth_refresh.rs, auth_login.rs, auth_token.rs, mod.rs Introduced the Refresh command for token refreshing, and updated login handling to improve clarity and user guidance on token expiration. Added new module for refresh commands.
crates/cli/src/updater.rs, workflows.rs Enhanced Updater struct with refresh token handling and updated methods for asynchronous operations, streamlining token management and retrieval processes.

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f79bc30 and 6718ee7.

Files selected for processing (10)
  • crates/auth/src/auth0.rs (5 hunks)
  • crates/auth/src/info.rs (3 hunks)
  • crates/auth/src/testing.rs (2 hunks)
  • crates/cli/src/commands/auth.rs (2 hunks)
  • crates/cli/src/commands/auth_login.rs (1 hunks)
  • crates/cli/src/commands/auth_refresh.rs (1 hunks)
  • crates/cli/src/commands/auth_token.rs (1 hunks)
  • crates/cli/src/commands/mod.rs (4 hunks)
  • crates/cli/src/updater.rs (8 hunks)
  • crates/cli/src/workflows.rs (3 hunks)
Files skipped from review due to trivial changes (1)
  • crates/cli/src/commands/auth_token.rs
Additional context used
Learnings (1)
Common learnings
Learnt from: morgante
URL: https://github.com/getgrit/gritql/pull/231

Timestamp: 2024-04-15T05:47:47.743Z
Learning: User morgante prefers not to be asked for documentation.
Additional comments not posted (27)
crates/cli/src/commands/auth_refresh.rs (1)

12-27: LGTM! Ensure proper error handling and logging.

The function correctly handles the token refresh process and logs the result. Ensure that the Updater and auth objects handle errors appropriately.

crates/cli/src/commands/auth.rs (2)

6-6: LGTM! Import is correct and necessary.

The import of RefreshAuthArgs is appropriate for the new Refresh command.


24-25: LGTM! Addition of the Refresh variant is correct.

The addition of the Refresh variant to the AuthCommands enum follows the existing pattern and is appropriate.

crates/cli/src/commands/auth_login.rs (2)

31-32: LGTM! Change improves readability.

Retrieving the token into a variable named token improves readability and allows for easier debugging or manipulation.


37-37: LGTM! Change enhances log clarity.

Logging the access_token field of the token enhances the clarity of the log output by focusing on the most relevant attribute for debugging.

crates/auth/src/testing.rs (3)

41-41: LGTM!

The addition of the refresh_token field initialized to None is correct and does not introduce any issues.


76-76: LGTM!

The addition of the refresh_token field initialized to None is correct and does not introduce any issues.


Line range hint 100-100: LGTM!

The addition of the refresh_token field initialized to None in the test function is correct and does not introduce any issues.

crates/auth/src/info.rs (4)

9-10: LGTM!

The addition of the refresh_token field to the AuthInfo struct is correct and does not introduce any issues.


12-18: LGTM!

The implementation of the From trait correctly includes the refresh_token field.


37-40: LGTM!

The new method correctly initializes the refresh_token field to None.


Line range hint 66-78: LGTM!

The fmt method correctly includes the refresh_token field.

crates/auth/src/auth0.rs (4)

54-56: LGTM!

The change to crate-private visibility for the access_token and refresh_token fields enhances encapsulation.


89-91: LGTM!

The token method correctly returns an AuthInfo object, aligning with the new token structure.


143-145: LGTM!

The poll method correctly handles the new token structure.


180-214: LGTM!

The refresh_token function is well-implemented, with appropriate error handling and logic to retain the old refresh token if the new response does not include one.

crates/cli/src/workflows.rs (2)

106-109: Ensure proper error handling for authentication.

The change to make get_valid_auth asynchronous is appropriate for non-blocking execution. However, ensure that all potential error cases are handled correctly, especially in a production environment.


Line range hint 208-219:
Ensure proper error handling for authentication.

The change to make get_valid_auth asynchronous is appropriate for non-blocking execution. However, ensure that all potential error cases are handled correctly, especially in a production environment.

crates/cli/src/commands/mod.rs (2)

8-8: LGTM!

The addition of the auth_refresh module aligns with the PR objective of adding the grit auth refresh command.


372-374: LGTM! But verify the handling of the new command.

The addition of the case to handle AuthCommands::Refresh is appropriate. Ensure that the new command is processed correctly in all relevant scenarios.

crates/cli/src/updater.rs (7)

146-146: LGTM!

The addition of the refresh_token field to the Manifest struct is appropriate for managing token refresh.


172-172: LGTM!

The addition of the refresh_token field to the Updater struct is appropriate for managing token refresh.


443-447: LGTM!

The changes to the save_token method ensure that both the access token and refresh token are saved correctly.


458-458: LGTM!

The changes to the delete_token method ensure that both the access token and refresh token are deleted correctly.


470-474: LGTM!

The changes to the get_auth method ensure that the AuthInfo struct includes the refresh_token if present.


479-491: LGTM!

The addition of the refresh_auth method ensures that the authentication token is refreshed and saved correctly.


494-503: LGTM!

The changes to the get_valid_auth method ensure that a valid authentication token is always available, refreshing it if necessary.


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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: 0

Outside diff range, codebase verification and nitpick comments (1)
crates/cli/src/commands/auth_refresh.rs (1)

1-4: Consider removing unused imports.

The colored::Colorize import is not used in the current code.

- use colored::Colorize;

@morgante morgante merged commit 3681506 into main Aug 5, 2024
10 checks passed
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.

1 participant