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

Cleanup the create account arguments so only including a profile is a valid path #297

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mj-palanker
Copy link
Contributor

@mj-palanker mj-palanker commented Feb 6, 2025

We now check the profile first, we merge the extra login/email args into it if provided, and get login/email from there directly.
This lets us totally ignore the login/email args on the cli if desired.
We also create a profile from the email/login provided for the old flow.

Summary by CodeRabbit

  • New Features
    • Enhanced the CLI account creation process by allowing users to supply a structured profile with login and email details, ensuring more streamlined inputs.
  • Bug Fixes
    • Improved error handling for empty or incorrectly formatted profile data during account creation.
  • Refactor
    • Updated validations and error feedback to ensure the profile data is correctly formatted, while maintaining support for existing input methods.

@mj-palanker mj-palanker requested a review from ggreer February 6, 2025 19:54
@mj-palanker mj-palanker requested a review from jirwin as a code owner February 6, 2025 19:54
Copy link

coderabbitai bot commented Feb 6, 2025

Walkthrough

The changes modify the account creation logic in the MakeMainCommand function within pkg/cli/commands.go. The flag check has been updated from "create-account-login" to "create-account-profile" to validate a structured profile map. The updated logic validates the profile, adds "login" and "email" if missing, and converts the map using structpb.NewStruct. A fallback to the previous login/email-based approach is maintained when no profile flag is provided.

Changes

File(s) Change Summary
pkg/cli/commands.go Updated account creation: now checks for "create-account-profile", validates the profile map, supplements missing "login" and "email", and converts the profile using structpb.NewStruct. Also retains fallback logic for legacy "create-account-login" and "create-account-email" flags.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant CLI as CLI Command
    participant CMD as MakeMainCommand
    participant Validator as Profile Checker
    participant Account as Account Creation

    User->>CLI: Run account creation command
    CLI->>CMD: Invoke MakeMainCommand
    CMD->>Validator: Check "create-account-profile" flag
    alt Profile flag present and valid
        Validator-->>CMD: Valid profile map returned
        CMD->>CMD: Add "login" and "email" if missing
        CMD->>Account: Create account with structured profile
        Account-->>CMD: Account successfully created
    else Profile flag missing/invalid
        CMD->>Account: Process using fallback login/email flags
        Account-->>CMD: Account created via fallback
    end
    CMD-->>CLI: Return account creation result
Loading

Possibly related PRs

Suggested reviewers

  • jirwin
  • ggreer

Poem

I'm a rabbit in the code, hopping through a maze,
Changing flags and profiles in so many clever ways.
Adding login and email with a spring in my stride,
Structuring the profile, nothing hidden to hide.
With a twitch of my nose, our code now shines bright!
🐰💻

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

@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

🧹 Nitpick comments (2)
pkg/cli/commands.go (2)

131-133: Improve error message clarity.

The error message when the profile is incorrectly formatted could be more helpful by showing the expected format.

Apply this diff to enhance the error message:

 if profileMap == nil {
-    return fmt.Errorf("create-account-profile is empty or incorrectly formatted: %v", v.GetString("create-account-profile"))
+    return fmt.Errorf("create-account-profile must be a valid JSON object, got: %v. Example format: '{\"login\":\"user\",\"email\":\"[email protected]\"}'", v.GetString("create-account-profile"))
 }

129-179: Architecture aligns well with PR objectives.

The implementation successfully:

  1. Makes profile-based account creation the primary path
  2. Merges login/email arguments into the profile when provided
  3. Maintains backward compatibility through the fallback path

This aligns perfectly with the PR's goal of cleaning up account creation arguments.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69e1f77 and db6fbd8.

📒 Files selected for processing (1)
  • pkg/cli/commands.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: go-test (1.22.x, windows-latest)
🔇 Additional comments (1)
pkg/cli/commands.go (1)

163-179: LGTM! Good fallback implementation.

The fallback logic maintains backward compatibility while creating a profile structure, aligning well with the PR's objective to make profile-based creation the primary path.

pkg/cli/commands.go Outdated Show resolved Hide resolved
Copy link

@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

🧹 Nitpick comments (2)
pkg/cli/commands.go (2)

131-133: Improve error message for profile validation.

The error message could be more helpful by providing guidance on the expected format.

-					return fmt.Errorf("create-account-profile is empty or incorrectly formatted: %v", v.GetString("create-account-profile"))
+					return fmt.Errorf("create-account-profile must be a non-empty map in the format '{\"key\":\"value\"}', got: %v", v.GetString("create-account-profile"))

144-154: Simplify login and email extraction.

The nested type assertions can be simplified for better readability.

-				login, email := "", ""
-				if l, ok := profileMap["login"]; ok {
-					if l, ok := l.(string); ok {
-						login = l
-					}
-				}
-				if e, ok := profileMap["email"]; ok {
-					if e, ok := e.(string); ok {
-						email = e
-					}
-				}
+				login := ""
+				if l, ok := profileMap["login"].(string); ok {
+					login = l
+				}
+				email := ""
+				if e, ok := profileMap["email"].(string); ok {
+					email = e
+				}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f8446b and 58ace9f.

📒 Files selected for processing (1)
  • pkg/cli/commands.go (2 hunks)
🔇 Additional comments (2)
pkg/cli/commands.go (2)

167-183: LGTM! Good fallback implementation.

The fallback logic correctly maintains backward compatibility by creating a profile from login and email when create-account-profile is not provided.


319-320: LGTM! Consistent provisioning support.

The changes correctly enable provisioning support for profile-based account creation in the GRPC server command.

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