Skip to content

Conversation

@Ice3man543
Copy link
Member

@Ice3man543 Ice3man543 commented Jul 11, 2025

Summary by CodeRabbit

  • New Features

    • Added verification checks for GCP providers to ensure credentials and service access at both project and organization levels. Users will now be alerted if there are issues accessing required GCP services.
  • Refactor

    • Improved internal variable naming for clarity.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1bf1103 and 6c85bf2.

📒 Files selected for processing (1)
  • pkg/providers/gcp/gcp.go (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
pkg/providers/gcp/gcp.go (2)
Learnt from: dogancanbakir
PR: projectdiscovery/cloudlist#687
File: pkg/providers/gcp/bucket.go:30-30
Timestamp: 2025-07-09T17:50:43.982Z
Learning: The Google Cloud Go SDK assetpb package does not have a ContentType_RESOURCE_AND_IAM_POLICY constant. The available constants are ContentType_RESOURCE and ContentType_IAM_POLICY as separate values. Using ContentType_RESOURCE appears to include IAM policy data in the response, allowing access to asset.IamPolicy.
Learnt from: dogancanbakir
PR: projectdiscovery/cloudlist#687
File: pkg/providers/gcp/bucket.go:30-30
Timestamp: 2025-07-09T17:50:43.982Z
Learning: In Google Cloud Go SDK's assetpb package, ContentType_RESOURCE includes IAM policy data when available. There is no ContentType_RESOURCE_AND_IAM_POLICY constant in the assetpb package. The correct approach is to use ContentType_RESOURCE and access asset.IamPolicy directly, as shown in the GCP provider implementations.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: release-test
  • GitHub Check: Test Builds (1.22.x, macOS-latest)
  • GitHub Check: Lint Test
  • GitHub Check: Test Builds (1.22.x, windows-latest)
  • GitHub Check: Test Builds (1.22.x, ubuntu-latest)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
pkg/providers/gcp/gcp.go (1)

324-324: LGTM! Improved variable naming.

The rename from assetTypes to assetTypesGcpListAPI makes the variable's purpose clearer.

Comment on lines +710 to +737
func (p *OrganizationProvider) Verify(ctx context.Context) error {
var assetTypesGcpListAPI = []string{
"compute.googleapis.com/Instance",
"compute.googleapis.com/Address",
"compute.googleapis.com/ForwardingRule",
"dns.googleapis.com/ManagedZone",
"dns.googleapis.com/ResourceRecordSet",
"storage.googleapis.com/Bucket",
"run.googleapis.com/Service",
"cloudfunctions.googleapis.com/CloudFunction",
"container.googleapis.com/Cluster",
"tpu.googleapis.com/Node",
"file.googleapis.com/Instance",
}

// For extra verification, try a minimal API call on one service
iter := p.assetClient.SearchAllResources(ctx, &assetpb.SearchAllResourcesRequest{
Scope: "organizations/" + p.organizationID,
AssetTypes: assetTypesGcpListAPI,
PageSize: 1,
})

_, err := iter.Next()
if err != nil && !errors.Is(err, iterator.Done) {
return errorutil.NewWithErr(err).Msgf("failed to verify GCP Asset API access for organization %s", p.organizationID)
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Extract duplicated asset types list to avoid maintenance issues.

The assetTypesGcpListAPI list is duplicated from the getAllAssets method (line 324). This violates the DRY principle and could lead to inconsistencies.

Extract the asset types list as a package-level variable:

// At the package level, after line 57
var assetTypesGcpListAPI = []string{
	"compute.googleapis.com/Instance",
	"compute.googleapis.com/GlobalAddress",
	"compute.googleapis.com/Address",
	"compute.googleapis.com/ForwardingRule",
	"dns.googleapis.com/ManagedZone",
	"dns.googleapis.com/ResourceRecordSet",
	"storage.googleapis.com/Bucket",
	"run.googleapis.com/Service",
	"cloudfunctions.googleapis.com/CloudFunction",
	"container.googleapis.com/Cluster",
	"tpu.googleapis.com/Node",
	"file.googleapis.com/Instance",
}

Then update both methods to use this shared variable:

  • Remove the local declaration at line 324 in getAllAssets
  • Remove the local declaration at line 711 in Verify
  • Update line 340 to use the package-level variable
  • Update line 728 to use the package-level variable

Note: The asset type compute.googleapis.com/GlobalAddress is missing from the Verify method's list but present in getAllAssets. Ensure both lists are consistent.

🤖 Prompt for AI Agents
In pkg/providers/gcp/gcp.go around lines 710 to 737, the assetTypesGcpListAPI
slice is duplicated from the getAllAssets method near line 324, causing
maintenance issues and inconsistencies. To fix this, extract the
assetTypesGcpListAPI slice as a package-level variable after line 57, including
the missing "compute.googleapis.com/GlobalAddress" entry. Then remove the local
declarations of this slice in both the Verify method (line 711) and getAllAssets
method (line 324), and update their usages at lines 728 and 340 respectively to
reference the new package-level variable.

Comment on lines +664 to +708
// Verify checks if the GCP provider credentials are valid
func (p *Provider) Verify(ctx context.Context) error {
if len(p.projects) == 0 {
return errorutil.New("no accessible GCP projects found with provided credentials")
}

// For extra verification, try a minimal API call on one service
var err error
for _, project := range p.projects {
var success bool
if p.compute != nil {
if _, err = p.compute.Regions.List(project).Do(); err == nil {
success = true
}
} else if p.dns != nil {
if _, err = p.dns.ManagedZones.List(project).Do(); err == nil {
success = true
}
} else if p.storage != nil {
if _, err = p.storage.Buckets.List(project).Do(); err == nil {
success = true
}
} else if p.functions != nil {
if _, err = p.functions.Projects.Locations.List(project).Do(); err == nil {
success = true
}
} else if p.run != nil {
if _, err = p.run.Projects.Locations.List(project).Do(); err == nil {
success = true
}
} else if p.gke != nil {
if _, err = p.gke.Projects.Locations.Clusters.List(project).Do(); err == nil {
success = true
}
}
// For any one service to be successful, we can return nil
if success {
return nil
}
}
if err != nil {
return errorutil.NewWithErr(err).Msgf("failed to verify GCP services")
}
return errorutil.New("no accessible GCP services found with provided credentials")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix error handling to preserve meaningful error messages.

The current implementation only preserves the last error, which might not be the most informative. Consider collecting errors from all attempts to provide better diagnostics.

Apply this diff to improve error handling:

 func (p *Provider) Verify(ctx context.Context) error {
 	if len(p.projects) == 0 {
 		return errorutil.New("no accessible GCP projects found with provided credentials")
 	}
 
 	// For extra verification, try a minimal API call on one service
-	var err error
+	var lastErr error
 	for _, project := range p.projects {
-		var success bool
 		if p.compute != nil {
-			if _, err = p.compute.Regions.List(project).Do(); err == nil {
-				success = true
+			if _, err := p.compute.Regions.List(project).Do(); err == nil {
+				return nil
+			} else {
+				lastErr = err
 			}
 		} else if p.dns != nil {
-			if _, err = p.dns.ManagedZones.List(project).Do(); err == nil {
-				success = true
+			if _, err := p.dns.ManagedZones.List(project).Do(); err == nil {
+				return nil
+			} else {
+				lastErr = err
 			}
 		} else if p.storage != nil {
-			if _, err = p.storage.Buckets.List(project).Do(); err == nil {
-				success = true
+			if _, err := p.storage.Buckets.List(project).Do(); err == nil {
+				return nil
+			} else {
+				lastErr = err
 			}
 		} else if p.functions != nil {
-			if _, err = p.functions.Projects.Locations.List(project).Do(); err == nil {
-				success = true
+			if _, err := p.functions.Projects.Locations.List(project).Do(); err == nil {
+				return nil
+			} else {
+				lastErr = err
 			}
 		} else if p.run != nil {
-			if _, err = p.run.Projects.Locations.List(project).Do(); err == nil {
-				success = true
+			if _, err := p.run.Projects.Locations.List(project).Do(); err == nil {
+				return nil
+			} else {
+				lastErr = err
 			}
 		} else if p.gke != nil {
-			if _, err = p.gke.Projects.Locations.Clusters.List(project).Do(); err == nil {
-				success = true
+			if _, err := p.gke.Projects.Locations.Clusters.List(project).Do(); err == nil {
+				return nil
+			} else {
+				lastErr = err
 			}
 		}
-		// For any one service to be successful, we can return nil
-		if success {
-			return nil
-		}
 	}
-	if err != nil {
-		return errorutil.NewWithErr(err).Msgf("failed to verify GCP services")
+	if lastErr != nil {
+		return errorutil.NewWithErr(lastErr).Msgf("failed to verify GCP services")
 	}
 	return errorutil.New("no accessible GCP services found with provided credentials")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Verify checks if the GCP provider credentials are valid
func (p *Provider) Verify(ctx context.Context) error {
if len(p.projects) == 0 {
return errorutil.New("no accessible GCP projects found with provided credentials")
}
// For extra verification, try a minimal API call on one service
var err error
for _, project := range p.projects {
var success bool
if p.compute != nil {
if _, err = p.compute.Regions.List(project).Do(); err == nil {
success = true
}
} else if p.dns != nil {
if _, err = p.dns.ManagedZones.List(project).Do(); err == nil {
success = true
}
} else if p.storage != nil {
if _, err = p.storage.Buckets.List(project).Do(); err == nil {
success = true
}
} else if p.functions != nil {
if _, err = p.functions.Projects.Locations.List(project).Do(); err == nil {
success = true
}
} else if p.run != nil {
if _, err = p.run.Projects.Locations.List(project).Do(); err == nil {
success = true
}
} else if p.gke != nil {
if _, err = p.gke.Projects.Locations.Clusters.List(project).Do(); err == nil {
success = true
}
}
// For any one service to be successful, we can return nil
if success {
return nil
}
}
if err != nil {
return errorutil.NewWithErr(err).Msgf("failed to verify GCP services")
}
return errorutil.New("no accessible GCP services found with provided credentials")
}
func (p *Provider) Verify(ctx context.Context) error {
if len(p.projects) == 0 {
return errorutil.New("no accessible GCP projects found with provided credentials")
}
// For extra verification, try a minimal API call on one service
var lastErr error
for _, project := range p.projects {
if p.compute != nil {
if _, err := p.compute.Regions.List(project).Do(); err == nil {
return nil
} else {
lastErr = err
}
} else if p.dns != nil {
if _, err := p.dns.ManagedZones.List(project).Do(); err == nil {
return nil
} else {
lastErr = err
}
} else if p.storage != nil {
if _, err := p.storage.Buckets.List(project).Do(); err == nil {
return nil
} else {
lastErr = err
}
} else if p.functions != nil {
if _, err := p.functions.Projects.Locations.List(project).Do(); err == nil {
return nil
} else {
lastErr = err
}
} else if p.run != nil {
if _, err := p.run.Projects.Locations.List(project).Do(); err == nil {
return nil
} else {
lastErr = err
}
} else if p.gke != nil {
if _, err := p.gke.Projects.Locations.Clusters.List(project).Do(); err == nil {
return nil
} else {
lastErr = err
}
}
}
if lastErr != nil {
return errorutil.NewWithErr(lastErr).Msgf("failed to verify GCP services")
}
return errorutil.New("no accessible GCP services found with provided credentials")
}
🤖 Prompt for AI Agents
In pkg/providers/gcp/gcp.go lines 664 to 708, the Verify function currently only
retains the last error encountered during service checks, which may lose
important diagnostic information. Modify the code to collect all errors from
each service check attempt, aggregate them, and return a combined error message
if no service verification succeeds. This will preserve meaningful error details
from all failed attempts for better troubleshooting.

@ehsandeep ehsandeep merged commit 15c9a23 into dev Jul 11, 2025
9 checks passed
@ehsandeep ehsandeep deleted the add-verify-gcp branch July 11, 2025 17:08
visnetodev pushed a commit to visnetotest/cloudlist that referenced this pull request Dec 7, 2025
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.

3 participants