add Verify method for Cloudflare to prevent full resource fetch#741
add Verify method for Cloudflare to prevent full resource fetch#741
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdded Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/providers/cloudflare/cloudflare_test.go (1)
91-159: Add aVerifytest for the non-DNS service path.Please add a case where
servicesdoes not include"dns"and assertVerifyreturnsnilwithout zone/DNS calls. This protects service-filter behavior.🧪 Suggested test extension
type trackingClient struct { zones []cloudflare.Zone + listZonesCalls int listDNSCalls int lastZoneID string lastListDNSParam cloudflare.ListDNSRecordsParams } func (t *trackingClient) ListZones(context.Context, ...string) ([]cloudflare.Zone, error) { + t.listZonesCalls++ return t.zones, nil } @@ +func TestProviderVerifySkipsWhenDNSServiceDisabled(t *testing.T) { + t.Parallel() + + client := &trackingClient{} + p := &Provider{ + id: "test", + client: client, + services: schema.ServiceMap{"workers": struct{}{}}, + } + + err := p.Verify(context.Background()) + require.NoError(t, err) + require.Zero(t, client.listZonesCalls) + require.Zero(t, client.listDNSCalls) +}As per coding guidelines, "Respect service filtering: Services() must list supported services, and providers should honor -s filters when gathering resources".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/providers/cloudflare/cloudflare_test.go` around lines 91 - 159, Add a new unit test that constructs a Provider with services NOT containing "dns" (e.g., services: schema.ServiceMap{}), a trackingClient that records calls, then calls Provider.Verify(ctx) and asserts no error is returned and that the client's zone/DNS call counters (e.g., trackingClient.listZonesCalls, trackingClient.listDNSCalls) remain zero; this verifies Provider.Verify honors the services filter and avoids contacting zones/records when DNS is not requested.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/providers/cloudflare/cloudflare.go`:
- Around line 103-114: In Verify, avoid calling the Cloudflare API when DNS is
not requested: move the p.services.Has("dns") check to the start of the DNS
verification path so the method returns early when "dns" is not enabled;
specifically update the Verify function so it checks p.services.Has("dns")
before invoking p.client.ListZones(ctx) (and only call ListZones, inspect zones,
or return the "no accessible zones" error when the service filter includes
"dns").
---
Nitpick comments:
In `@pkg/providers/cloudflare/cloudflare_test.go`:
- Around line 91-159: Add a new unit test that constructs a Provider with
services NOT containing "dns" (e.g., services: schema.ServiceMap{}), a
trackingClient that records calls, then calls Provider.Verify(ctx) and asserts
no error is returned and that the client's zone/DNS call counters (e.g.,
trackingClient.listZonesCalls, trackingClient.listDNSCalls) remain zero; this
verifies Provider.Verify honors the services filter and avoids contacting
zones/records when DNS is not requested.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 86c62ec3-cef5-427b-9b21-9a8c9d0c8f89
📒 Files selected for processing (2)
pkg/providers/cloudflare/cloudflare.gopkg/providers/cloudflare/cloudflare_test.go
Summary by CodeRabbit