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: send user name with workflow requests #373

Merged
merged 3 commits into from
Jun 18, 2024
Merged

feat: send user name with workflow requests #373

merged 3 commits into from
Jun 18, 2024

Conversation

morgante
Copy link
Contributor

@morgante morgante commented Jun 18, 2024

This allows (light) personalization in workflows.

Greptile Summary

This is an auto-generated summary

  • Introduced HasuraClaims struct to handle additional JWT claims
  • Added get_user_name method to AuthInfo struct
  • Included user's VCS username in workflow requests
  • Added log statement to display authenticated user's name in doctor.rs
  • Refactored authentication token retrieval for better error handling

Summary by CodeRabbit

  • New Features

    • Added nickname support in authentication payloads.
    • Introduced user-friendly logging of authentication usernames in doctor checks.
  • Style

    • Improved visibility of expired authentication token messages with red and bold formatting.
  • Refactor

    • Streamlined authentication handling by encapsulating token access and integrating usernames conditionally.

@morgante morgante requested a review from a team as a code owner June 18, 2024 16:34
Copy link
Contributor

coderabbitai bot commented Jun 18, 2024

Walkthrough

Walkthrough

The code changes across multiple files primarily focus on enhancing authentication mechanisms by introducing new structures and methods. Key modifications include adding a HasuraClaims struct with a nickname field, updating the AuthInfoPayload struct to include optional hasura_claims, and implementing a method to extract a user's nickname. Additionally, there's improved logging and formatting, refactored imports for better organization, and insertion of the username into the input payload in the CLI workflows.

Changes

Files Change Summary
crates/auth/src/info.rs Added HasuraClaims struct, modified AuthInfoPayload to include hasura_claims, added get_user_name method to AuthInfo.
crates/cli/src/commands/doctor.rs Added logging for authentication username, changed color formatting for expired token message to red and bold.
crates/cli/src/workflows.rs Refactored imports, added constant GRIT_VCS_USER_NAME, updated authentication handling, inserted username into input payload.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Auth
    participant Server

    User->>CLI: Run Command
    CLI->>Auth: Fetch Auth Information
    Auth-->>CLI: Return `AuthInfoPayload` with `hasura_claims`
    CLI->>CLI: Extract `nickname` from `AuthInfoPayload`
    CLI->>CLI: Log username
    CLI->>Server: Send Request with `nickname`
    Server-->>CLI: Return Response
    CLI-->>User: Display Response
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 98eb9d3 and 748230e.

Files selected for processing (3)
  • crates/auth/src/info.rs (3 hunks)
  • crates/cli/src/commands/doctor.rs (1 hunks)
  • crates/cli/src/workflows.rs (6 hunks)
Additional context used
Learnings (1)
Common learnings
User: 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.
Gitleaks
crates/auth/src/info.rs

84-84: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data. (jwt)

Additional comments not posted (5)
crates/auth/src/info.rs (3)

11-15: Introduced HasuraClaims struct with nickname field correctly mapped using serde(rename). This change aligns with the PR's objective to handle user names.


21-22: Added hasura_claims field to AuthInfoPayload struct, using Option to handle cases where claims might not be present. Proper use of serde(rename) for JSON mapping.


48-51: Implemented get_user_name method in AuthInfo to fetch the user's nickname from hasura_claims. Proper error handling and return type usage.

crates/cli/src/commands/doctor.rs (1)

89-96: Enhanced run_doctor function to log the authenticated user's name and handle token expiration with appropriate color formatting. These changes improve user experience and align with the PR's objectives.

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

104-114: Updated run_bin_workflow function to include the authenticated user's name in the input payload when available. This change supports the new personalization feature effectively.


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 Configration 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

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

LGTM

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

#[test]
fn test_get_user_name() {
// This token is safe, it isn't signed by a real authority - only use for testing
let jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWRlZmF1bHQtcm9sZSI6InVzZXIiLCJ4LWhhc3VyYS1hbGxvd2VkLXJvbGVzIjpbInVzZXIiXSwieC1oYXN1cmEtdXNlci1pZCI6ImdpdGh1YnwxNjI3ODAxIiwieC1oYXN1cmEtcmF3LW5pY2tuYW1lIjoibW9yZ2FudGUiLCJ4LWhhc3VyYS11c2VyLXRlbmFudCI6ImdpdGh1YiIsIngtaGFzdXJhLWF1dGgtcHJvdmlkZXIiOiJnaXRodWIiLCJ4LWhhc3VyYS11c2VyLW5pY2tuYW1lIjoiZ2l0aHVifG1vcmdhbnRlIn0sImlzcyI6Imh0dHBzOi8vYXV0aDAuZ3JpdC5pby8iLCJzdWIiOiJnaXRodWJ8MTYyNzgwMSIsImF1ZCI6Imh0dHBzOi8vYXBpMi5ncml0LmlvIiwiaWF0IjoxNzE4NzI2MzUzLCJleHAiOjE3MTg4MTI3NTN9.eEU0bSldfdxuWpXAKfWAuJBqTMR5BAdnAEhFu-hVlI4";
Copy link
Contributor

Choose a reason for hiding this comment

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

The hardcoded JWT in the test might pose a security risk if exposed in public repositories. Consider obfuscating it or using mock libraries to handle JWTs in tests.

Tools
Gitleaks

84-84: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data. (jwt)

@morgante morgante merged commit 675d2ed into main Jun 18, 2024
9 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.

2 participants