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

Return a different error message if --provisioning flag is not set #233

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mchavez
Copy link
Contributor

@mchavez mchavez commented Sep 23, 2024

  • Return a different error message if --provisioning flag is not set
    Right now if you try to provision something without the --provisioning flag, we error with "resource type does not have provisioner configured". This error message should be something like "provisioning is not enabled. try running with --provisioning".

Fixes #114.

Summary by CodeRabbit

  • New Features

    • Introduced a new validation step for provisioning configuration, enhancing error handling for entitlement grants.
  • Bug Fixes

    • Improved error messaging consistency by using a centralized constant for provisioning-related errors.
  • Refactor

    • Streamlined logic in the Grant and Revoke methods for improved readability and maintainability.

Copy link

coderabbitai bot commented Sep 23, 2024

Walkthrough

The changes involve refactoring error handling and control flow in the codebase related to provisioning. Hardcoded error messages have been replaced with a constant variable for better maintainability. Additionally, a new validation step has been introduced to check whether provisioning is enabled before executing certain operations. This ensures that users receive clearer error messages when attempting to provision resources without the necessary configuration.

Changes

Files Change Summary
internal/connector/noop_provisioner.go, pkg/cli/commands.go, pkg/connectorbuilder/connectorbuilder.go Refactored error handling by replacing hardcoded messages with a constant ProvisioningNotEnabledMsg. Introduced a new variable isProvisioning in the CLI commands to validate provisioning status. Refactored Grant and Revoke methods for better readability and consistency in error reporting.

Assessment against linked issues

Objective Addressed Explanation
Return a different error message if --provisioning is not set (#114)
Ensure clearer messaging when provisioning is not enabled

Poem

In the code where bunnies hop,
Messages now won't make you stop.
With constants bright, they shine so clear,
"Provisioning's off!" you’ll now hear.
So run your tasks without a fright,
Our code is tidy, and all feels right! 🐇✨


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

@mchavez mchavez marked this pull request as ready for review September 23, 2024 16:51
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

Outside diff range and nitpick comments (2)
pkg/connectorbuilder/connectorbuilder.go (2)

Line range hint 540-566: Improved error handling and messaging in the Grant method

The changes enhance the error reporting by using a standardized message (connector.ProvisioningNotEnabledMsg) when provisioning is not enabled. This aligns well with the PR objectives to provide clearer error messages.

Consider adding the error message to the log output on line 565 for consistency:

-l.Error(connector.ProvisioningNotEnabledMsg, zap.String("resource_type", rt))
+l.Error("error: grant failed", zap.Error(errors.New(connector.ProvisioningNotEnabledMsg)), zap.String("resource_type", rt))

This change would make the error logging consistent with other error logs in the method and provide more context in the logs.


Line range hint 574-600: Improved error handling and messaging in the Revoke method

The changes in the Revoke method mirror those in the Grant method, enhancing error reporting by using a standardized message (connector.ProvisioningNotEnabledMsg) when provisioning is not enabled. This is consistent with the PR objectives and improves the overall error handling in the connector.

For consistency with the Grant method and other error logs, consider modifying the error logging on line 598:

-l.Error(connector.ProvisioningNotEnabledMsg, zap.String("resource_type", rt))
+l.Error("error: revoke failed", zap.Error(errors.New(connector.ProvisioningNotEnabledMsg)), zap.String("resource_type", rt))

This change would provide more context in the logs and maintain consistency across error reporting in the file.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2238ed2 and b25e864.

Files selected for processing (3)
  • internal/connector/noop_provisioner.go (1 hunks)
  • pkg/cli/commands.go (3 hunks)
  • pkg/connectorbuilder/connectorbuilder.go (5 hunks)
Additional comments not posted (10)
internal/connector/noop_provisioner.go (8)

13-14: LGTM: New constant improves clarity and maintainability

The new ProvisioningNotEnabledMsg constant effectively addresses the PR objectives by providing a clearer error message. It correctly suggests using the --provisioning flag, which aligns with the requirements. Using a constant also improves code maintainability by centralizing the error message.


16-16: LGTM: Improved error handling in Grant method

The Grant method now correctly uses the new ProvisioningNotEnabledMsg constant, which aligns with the PR objectives. The use of status.Error with codes.FailedPrecondition is appropriate for this scenario, providing a clear and consistent error message.


20-20: LGTM: Consistent error handling in Revoke method

The Revoke method now uses the ProvisioningNotEnabledMsg constant, maintaining consistency with the Grant method and aligning with the PR objectives. The error handling approach remains appropriate and consistent.


24-24: LGTM: Consistent error handling in CreateResource method

The CreateResource method now uses the ProvisioningNotEnabledMsg constant, maintaining consistency with other methods and aligning with the PR objectives. The error handling approach remains appropriate and consistent.


28-28: LGTM: Consistent error handling in DeleteResource method

The DeleteResource method now uses the ProvisioningNotEnabledMsg constant, maintaining consistency with other methods and aligning with the PR objectives. The error handling approach remains appropriate and consistent.


32-32: LGTM: Consistent error handling in RotateCredential method

The RotateCredential method now uses the ProvisioningNotEnabledMsg constant, maintaining consistency with other methods and aligning with the PR objectives. The error handling approach remains appropriate and consistent.


36-36: LGTM: Consistent error handling in CreateAccount method

The CreateAccount method now uses the ProvisioningNotEnabledMsg constant, maintaining consistency with other methods and aligning with the PR objectives. The error handling approach remains appropriate and consistent.


13-36: Summary: Excellent improvements in error handling and message clarity

The changes in this file effectively address the PR objectives and the linked issue (#114). By introducing the ProvisioningNotEnabledMsg constant and consistently using it across all methods of the noopProvisioner struct, the code now provides a clearer and more informative error message when provisioning is not enabled.

Key improvements:

  1. Enhanced user experience with a more descriptive error message.
  2. Improved code maintainability by centralizing the error message in a constant.
  3. Consistent error handling across all methods.

These changes will help users understand the need for the --provisioning flag more easily, potentially reducing confusion and support requests.

pkg/cli/commands.go (2)

21-22: Approved: Necessary imports added

The imports of codes and status from google.golang.org/grpc are necessary for proper error handling using gRPC status codes.


70-70: Approved: Variable isProvisioning correctly captures certain provisioning actions

The introduction of the isProvisioning variable appropriately checks if the grant-entitlement or revoke-grant flags are set, indicating provisioning actions.

Comment on lines +89 to +91
if isProvisioning && !v.GetBool("provisioning") {
return status.Error(codes.Unimplemented, connector.ProvisioningNotEnabledMsg)
}
Copy link

@coderabbitai coderabbitai bot Sep 23, 2024

Choose a reason for hiding this comment

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

Issue: isProvisioning does not account for all provisioning commands

The current condition for isProvisioning only checks the grant-entitlement and revoke-grant flags. However, other commands like create-account-login, delete-resource, and rotate-credentials also perform provisioning actions. This omission could lead to situations where users do not receive the intended error message when provisioning is disabled but attempt these actions.

Apply this diff to include all provisioning-related flags in the isProvisioning variable:

-isProvisioning := v.GetString("grant-entitlement") != "" || v.GetString("revoke-grant") != ""
+isProvisioning := v.GetString("grant-entitlement") != "" ||
+	v.GetString("revoke-grant") != "" ||
+	v.GetString("create-account-login") != "" ||
+	v.GetString("delete-resource") != "" ||
+	v.GetString("rotate-credentials") != ""

Committable suggestion was skipped due to low confidence.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mchavez is this true?

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

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.

baton-sdk should return a different error message if --provisioning is not set
2 participants