Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Guard cloud service #6053

Merged
merged 3 commits into from
Feb 19, 2025
Merged

Guard cloud service #6053

merged 3 commits into from
Feb 19, 2025

Conversation

dogancanbakir
Copy link
Member

@dogancanbakir dogancanbakir commented Feb 16, 2025

Proposed changes

Closes #6050

in case of empty or missing creds:

$ go run . -ai "find critical bugs"
[WRN] To utilize the `-ai` flag, please configure your API key with the `-auth` flag or set the `PDCP_API_KEY` environment variable

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • New Features
    • Enhanced console output now displays color-coded warnings.
    • Introduced a check for necessary API key configuration when using advanced prompt features. If credentials are missing, a clear, user-facing warning prompts proper setup and the program exits gracefully.

@dogancanbakir dogancanbakir self-assigned this Feb 16, 2025
@auto-assign auto-assign bot requested a review from dwisiswant0 February 16, 2025 19:14
Copy link
Contributor

coderabbitai bot commented Feb 16, 2025

Walkthrough

The changes introduce a new conditional block in the main application entry point that checks if the AITemplatePrompt option is set. If specified, the code attempts to retrieve credentials using the PDCPCredHandler. If the credentials are unavailable, a fatal error message is logged, instructing the user to configure their API key through the -auth flag or by setting the PDCP_API_KEY environment variable. This enhances error handling for the AI template prompt feature.

Changes

File(s) Change Summary
cmd/nuclei/main.go - Introduced a conditional check for the AITemplatePrompt option which retrieves credentials via PDCPCredHandler. If credentials are missing, logs a fatal error message instructing user to configure API key.

Possibly related PRs

Suggested reviewers

  • ehsandeep

Poem

I'm a rabbit coding through the night,
With checks for credentials, all feels right.
If keys are missing, a message will say,
"Configure your API, don't delay!"
Hopping along, with each little tweak,
Celebrating changes, oh what a peak!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e29fa7 and 51c07a7.

📒 Files selected for processing (1)
  • cmd/nuclei/main.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/nuclei/main.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint

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

🧹 Nitpick comments (1)
cmd/nuclei/main.go (1)

530-538: LGTM with minor suggestions!

The credential check is well-implemented with clear user guidance. Consider two improvements:

  1. Use a non-zero exit code (e.g., 1) to indicate a configuration error
  2. Extract the warning message to a constant for reusability

Apply this diff to improve the implementation:

+const (
+    errMissingAPIKey = "[%v] To utilize the `-ai` flag, please configure your API key with the `-auth` flag or set the `PDCP_API_KEY` environment variable"
+)

 if options.AITemplatePrompt != "" {
     h := &pdcp.PDCPCredHandler{}
     _, err := h.GetCreds()
     if err != nil {
-        gologger.Print().Msgf("%s", fmt.Sprintf("[%v] To utilize the `-ai` flag, please configure your API key with the `-auth` flag or set the `PDCP_API_KEY` environment variable", aurora.NewAurora(!options.NoColor).BrightYellow("WRN")))
-        os.Exit(0)
+        gologger.Print().Msgf("%s", fmt.Sprintf(errMissingAPIKey, aurora.NewAurora(!options.NoColor).BrightYellow("WRN")))
+        os.Exit(1)
     }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dabcce8 and 2e29fa7.

📒 Files selected for processing (1)
  • cmd/nuclei/main.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint
🔇 Additional comments (1)
cmd/nuclei/main.go (1)

16-16: LGTM!

The aurora package is appropriately imported for colored console output.

@dwisiswant0
Copy link
Member

I think this should return a fatal error instead of just a warning and exit with a code >0.

@dogancanbakir
Copy link
Member Author

@dwisiswant0 Absolutely! I was attempting to make modifications in the library and chose to do them here; I probably left things unchanged after the copy/paste 🤦‍♂️ Good catch!

@ehsandeep ehsandeep merged commit 89c77d1 into dev Feb 19, 2025
20 checks passed
@ehsandeep ehsandeep deleted the guard_cloud_service branch February 19, 2025 10:51
@ehsandeep ehsandeep added this to the Nuclei v3.3.10 milestone Feb 20, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
3 participants