Skip to content

refactor(service): extract shared SSRF options helper to pkg/ssrfopt#29

Merged
alexgarzao merged 3 commits into
developfrom
refactor/extract-ssrf-options
May 21, 2026
Merged

refactor(service): extract shared SSRF options helper to pkg/ssrfopt#29
alexgarzao merged 3 commits into
developfrom
refactor/extract-ssrf-options

Conversation

@alexgarzao
Copy link
Copy Markdown
Collaborator

@alexgarzao alexgarzao commented May 15, 2026

Summary

Extracts the duplicated ssrfOptions() helper into a new shared package pkg/ssrfopt. Originally targeted three call sites (command + midaz + tracer); after rebasing on develop, the command path no longer uses ssrfOptions() directly — PR #25 migrated it to safehttp.Validate, which encapsulates SSRF policy internally. This refactor now consolidates the remaining duplication between midaz and tracer probers.

Pure refactor, zero behavior change.

What changed

New package pkg/ssrfopt with two exported symbols:

  • Options() []libSSRF.Option — lazily-cached env-var lookup (SSRF_ALLOW_PRIVATE).
  • ResetCache() — test-only escape hatch (godoc-tagged), so test files can flip SSRF_ALLOW_PRIVATE via t.Setenv between scenarios.

Two call sites updated:

  • pkg/executors/midaz/connectivity_prober.go
  • pkg/executors/tracer/connectivity_prober.go

Two helper files deleted:

  • pkg/executors/midaz/ssrf_test_helpers.go — wrapped resetMidazSSRFCache, now folded into the shared package.
  • pkg/executors/tracer/ssrf_test_helpers.go — same, for tracer.

Net impact

Single source of truth for SSRF policy across the remaining outbound probes. Future providers that add their own ConnectivityProber (e.g., S3) consume ssrfopt.Options() instead of cloning the helper.

Rebase / retarget notes (2026-05-21)

PR was originally based on feature/connectivity-prober-tracer (PR #25's branch). After #25 merged to develop:

So the original "rule-of-three" premise narrowed to rule-of-two (midaz + tracer), but the deduplication still earns its keep — ssrfOptions() was a non-trivial helper (env-var caching + lazy init) duplicated verbatim across both probers.

Naming and design decisions

Decision Choice Rationale
Package name pkg/ssrfopt (flat, not pkg/ssrf/options) Matches existing flat convention (pkg/clock, pkg/contextutil); only 2 exported symbols, nesting would be over-structured.
ResetCache exposure Exported unconditionally with godoc "TEST-ONLY" marker Two test packages need it; a //go:build unit tag would force tag interactions in every consumer test. Godoc is clear enough that no production caller will reach for it.

Test plan

  • go build ./... — clean.
  • go test ./... — 240 pass across 53 packages (the new pkg/ssrfopt adds 1 package).
  • make lint — 0 issues.
  • make sec — 0 issues.
  • No behavior change. Same env var, same libSSRF.WithAllowPrivateNetwork option, same caching semantics — just centralized.

Reviewer checklist

  1. Verify pkg/ssrfopt/options.go matches the semantics of the old per-package ssrfOptions() (env-var name, libSSRF option set, lazy caching via sync.Once).
  2. Verify no test broke (ResetCache correctly resets between subtests in both midaz and tracer suites).

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (1)
  • develop

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6f77d66a-2c7d-44f3-a335-ae76c3646e94

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

@alexgarzao alexgarzao changed the title refactor(ssrfopt): extract shared SSRF options helper to pkg/ssrfopt refactor(service): extract shared SSRF options helper to pkg/ssrfopt May 15, 2026
Adds pkg/ssrfopt with Options() and ResetCache() centralizing the
SSRF_ALLOW_PRIVATE env-var lookup that was duplicated across three
sites (command, midaz prober, tracer prober).

Naming rationale: pkg/ssrfopt (over pkg/ssrf/options) because the
package's whole purpose is a 2-symbol API and a flat path matches
the existing pkg/clock, pkg/contextutil convention.

ResetCache is exported unconditionally (not behind //go:build unit)
rather than duplicated in three _test_helpers.go files. The package
is plumbing-only with a tiny surface and the godoc clearly marks
ResetCache as test-only.
Removes the local ssrfOptions helper, its ssrfAllowPrivate /
ssrfAllowPrivateOnce cache vars, and the entire ssrf_test_helpers.go
(resetMidazSSRFCache) from the midaz prober package. The prober now
calls ssrfopt.Options() and the test resetSSRFCacheForTest delegates
to ssrfopt.ResetCache().

Net result: one fewer file in the package (ssrf_test_helpers.go gone)
and a single line where there used to be a ~30-line duplicate block.

Pure refactor — no behaviour change. All 24 tests in
./pkg/executors/midaz/... pass under -tags=unit.
Removes the local ssrfOptions helper, its ssrfAllowPrivate /
ssrfAllowPrivateOnce cache vars, and the entire ssrf_test_helpers.go
(resetTracerSSRFCache) from the tracer prober package. The prober now
calls ssrfopt.Options() and all 8 test sites that previously called
resetTracerSSRFCache() now call ssrfopt.ResetCache() directly.

This is the third (last) consumer to migrate to the shared package,
closing out the rule-of-three TODO that the original tracer prober PR
flagged in its source comments.

Pure refactor — no behaviour change. All 14 tests in
./pkg/executors/tracer/... pass under -tags=unit.
@alexgarzao alexgarzao force-pushed the refactor/extract-ssrf-options branch from e9a202d to b88c723 Compare May 21, 2026 20:04
@alexgarzao alexgarzao changed the base branch from feature/connectivity-prober-tracer to develop May 21, 2026 20:04
@alexgarzao alexgarzao merged commit 0a3b6f6 into develop May 21, 2026
1 check passed
alexgarzao added a commit that referenced this pull request May 21, 2026
The skeleton on line 145 still used the old `ssrfOptions()` identifier,
inconsistent with the surrounding text (line 161) that already directs
readers to use the shared `pkg/ssrfopt.Options()` helper. After PR #29
merged, `ssrfOptions()` no longer exists in any prober — the canonical
name is `ssrfopt.Options()`. Update the example so it matches both the
explanatory text below it and the real implementations in midaz/tracer.
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.

1 participant