Skip to content

fix missing prefix while listing cloud run resources#748

Merged
mkrs2404 merged 1 commit intodevfrom
fix-cloud-run-list
Apr 29, 2026
Merged

fix missing prefix while listing cloud run resources#748
mkrs2404 merged 1 commit intodevfrom
fix-cloud-run-list

Conversation

@mkrs2404
Copy link
Copy Markdown
Contributor

@mkrs2404 mkrs2404 commented Apr 29, 2026

closes #747

Summary by CodeRabbit

  • Bug Fixes
    • Resolved Cloud Run service enumeration issue by constructing properly formatted fully qualified parent paths for service discovery, ensuring consistent handling across different location formats.
    • Added warning messages for Cloud Run location and service enumeration failures, providing enhanced visibility into issues while the system continues processing remaining items.

@mkrs2404 mkrs2404 requested a review from Ice3man543 April 29, 2026 12:11
@mkrs2404 mkrs2404 self-assigned this Apr 29, 2026
@neo-by-projectdiscovery-dev
Copy link
Copy Markdown

neo-by-projectdiscovery-dev Bot commented Apr 29, 2026

Neo - PR Security Review

No security issues found

Hardening Notes
  • The PR adds proper error logging with gologger for better observability when listing Cloud Run resources
  • All fmt.Sprintf usage involves trusted data from GCP API responses (project IDs and location IDs), not user-controlled input

Comment @pdneo help for available commands. · Open in Neo

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

Walkthrough

The Cloud Run service enumeration now constructs the fully qualified parent path (projects/<project>/locations/<location.LocationId>) before calling the Cloud Run API, fixing silent enumeration failures caused by the Knative API's truncated location name format. Warning logs added for location and service listing errors.

Changes

Cohort / File(s) Summary
Cloud Run Service Enumeration
pkg/providers/gcp/cloud-run.go
Constructs fully qualified parent path by prepending projects/ prefix to location reference before API calls. Adds gologger.Warning() messages when location listing or service listing fails, while continuing to process remaining items.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A path was broken, truncated and wrong,
Services vanished, though they thrived all along.
With projects/ prepended, the listing runs true,
Now warnings log clearly what's old and what's new! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing a missing prefix issue when listing Cloud Run resources, which directly addresses the root cause in the linked issue.
Linked Issues check ✅ Passed The code change directly resolves the root cause: constructing the fully qualified parent with 'projects/' prefix before calling Services.List(), eliminating the silent empty results when enumerating Cloud Run services.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the Cloud Run enumeration issue. The modification to construct the correct parent format and addition of warning logs are directly necessary to resolve issue #747.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-cloud-run-list

Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/providers/gcp/cloud-run.go (1)

53-74: ⚠️ Potential issue | 🟠 Major

Propagate context.Context through Cloud Run discovery loop.

getServices() ignores cancellation while iterating projects/locations, so discovery can continue after Resources(ctx) is canceled.

Proposed patch
 func (d *cloudRunProvider) GetResource(ctx context.Context) (*schema.Resources, error) {
 	list := schema.NewResources()
-	services, err := d.getServices()
+	services, err := d.getServices(ctx)
 	if err != nil {
 		return nil, fmt.Errorf("could not get services: %s", err)
 	}
@@
-func (d *cloudRunProvider) getServices() ([]*run.Service, error) {
+func (d *cloudRunProvider) getServices(ctx context.Context) ([]*run.Service, error) {
 	var services []*run.Service
 	for _, project := range d.projects {
+		if err := ctx.Err(); err != nil {
+			return services, err
+		}
 		locationsService := d.run.Projects.Locations.List(fmt.Sprintf("projects/%s", project))
 		locationsResponse, err := locationsService.Do()
 		if err != nil {
 			gologger.Warning().Msgf("could not list cloud run locations for project %s: %s", project, err)
 			continue
 		}
 
 		for _, location := range locationsResponse.Locations {
+			if err := ctx.Err(); err != nil {
+				return services, err
+			}
 			// build the parent explicitly because the location.Name is not returned with the projects/ prefix in Knative API
 			parent := fmt.Sprintf("projects/%s/locations/%s", project, location.LocationId)
 			servicesResponse, err := d.run.Projects.Locations.Services.List(parent).Do()

As per coding guidelines, "Always pass and honor context.Context in Resources() and long-running API calls to support cancellation".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/providers/gcp/cloud-run.go` around lines 53 - 74, getServices() ignores
cancellation; change its signature to accept context.Context (e.g.,
getServices(ctx context.Context)) and propagate the context from Resources(ctx)
into it, then apply the context to the long-running GCP calls by calling
Context(ctx) on the returned call objects before Do() (for example, use
d.run.Projects.Locations.List(...).Context(ctx).Do() and
d.run.Projects.Locations.Services.List(parent).Context(ctx).Do()); update any
callers (Resources or others) to pass the ctx through so discovery honors
cancellation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@pkg/providers/gcp/cloud-run.go`:
- Around line 53-74: getServices() ignores cancellation; change its signature to
accept context.Context (e.g., getServices(ctx context.Context)) and propagate
the context from Resources(ctx) into it, then apply the context to the
long-running GCP calls by calling Context(ctx) on the returned call objects
before Do() (for example, use
d.run.Projects.Locations.List(...).Context(ctx).Do() and
d.run.Projects.Locations.Services.List(parent).Context(ctx).Do()); update any
callers (Resources or others) to pass the ctx through so discovery honors
cancellation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e033d764-e877-482f-8826-a420b2cc7735

📥 Commits

Reviewing files that changed from the base of the PR and between d5d9036 and 4070742.

📒 Files selected for processing (1)
  • pkg/providers/gcp/cloud-run.go

@mkrs2404 mkrs2404 requested a review from knakul853 April 29, 2026 12:30
@mkrs2404 mkrs2404 merged commit c3dc404 into dev Apr 29, 2026
10 checks passed
@mkrs2404 mkrs2404 deleted the fix-cloud-run-list branch April 29, 2026 13:01
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.

Cloud Run enumeration silently returns zero services

2 participants