Skip to content

chore: extract reverse proxy from pkg/gateway into pkg/edge (Phase 2)#46

Merged
Viridian-Inc merged 1 commit into
mainfrom
chore/extract-edge-package
May 2, 2026
Merged

chore: extract reverse proxy from pkg/gateway into pkg/edge (Phase 2)#46
Viridian-Inc merged 1 commit into
mainfrom
chore/extract-edge-package

Conversation

@Viridian-Inc
Copy link
Copy Markdown
Owner

Summary

Closes the original Phase 2 from #37. With observability primitives now in `pkg/observability` (#44), the L7 reverse proxy and its TLS-cert helper can finally leave `pkg/gateway` without circular imports.

Moved verbatim into `pkg/edge`:

  • `proxy.go` — `ProxyRoute`, `ProxyServer`, `ServicePorts`, `BuildRoutes`, `BuildRoutesWithPorts`, `NewProxyServer{,WithOpts}`, `StartProxy{,WithOpts}`, `ProxyOpts`, plus internal handlers.
  • `certs.go` — `CertPair`, `EnsureCerts`, all OS trust helpers, file/PEM I/O.
  • Tests come along.

Internal references to `RequestLog`/`RequestStats`/`RequestBroadcaster`/`RequestEntry`/`GenerateTraceID` updated to import from `pkg/observability` directly (no longer go through gateway aliases).

`pkg/gateway/proxy.go` and `pkg/gateway/certs.go` shrink to type aliases + forwarder functions so historical importers continue to compile. `cmd/gateway/main.go` migrated to import `pkg/edge` directly.

Closes #45.

Behavior

Zero behavioral change. Wire format on `/api/proxy/routes` is byte-identical, route matching is identical, TLS cert lifecycle is identical.

Status of the original three-way split

Concern Home
DNS server `pkg/dns` (#38)
AWS endpoint resolver `pkg/awsendpoints` (#38)
Observability primitives `pkg/observability` (#44)
Reverse proxy `pkg/edge` (this PR)

`pkg/gateway` now owns just the AWS API mock handler + IAM middleware + the `LoggingMiddleware` that wraps it. The package name finally describes what it does.

Test plan

  • `go build ./...`
  • `go test ./pkg/edge/... ./pkg/gateway/... ./pkg/admin/... ./pkg/observability/... ./cmd/gateway/...` — all green
  • `go test -short ./pkg/... ./services/...` — all green except the same pre-existing `pkg/platform/store` testcontainers/Docker failure
  • `go vet ./pkg/edge/... ./pkg/gateway/... ./cmd/gateway/...`

Out of scope

  • Phase 3 — extracting the AWS gateway handler itself into `pkg/awsgateway`. The 77-importer ecosystem (mostly service tests using `gateway.RequestEntry`) is already insulated by the PR chore: extract observability data types into pkg/observability (Phase 2 prep) #44 aliases, so Phase 3 is now also unblocked, but it's a different shape of refactor (renaming the package containing the handler vs. moving siblings out of it) and worth its own ticket.
  • Removing the dead-code `proxyTo` / `proxyToPreserveHost` helpers in the moved file — preserved for minimum-invasive structural move.
  • Adding a `Service string` field to `ProxyRoute` to retire the string-match service detection in `logProxyRequest` (the wart I flagged in the conversation that triggered this chain).

🤖 Generated with Claude Code

Closes the original Phase 2 from #37. With observability primitives now in
pkg/observability (#44), the L7 reverse proxy and its TLS-cert helper can
finally leave pkg/gateway without circular imports.

Moved verbatim into pkg/edge:
- proxy.go: ProxyRoute, ProxyServer, ServicePorts, BuildRoutes,
  BuildRoutesWithPorts, NewProxyServer{,WithOpts}, StartProxy{,WithOpts},
  ProxyOpts, plus all internal handlers (logProxyRequest,
  proxyToWithOpts, addCORSHeaders, rewriteResponseBody,
  isWebSocketUpgrade, proxyWebSocket, statusRecorder).
- certs.go: CertPair, EnsureCerts, all OS trust helpers, file/PEM I/O.
- proxy_test.go and certs_test.go.

Internal references to RequestLog / RequestStats / RequestBroadcaster /
RequestEntry / GenerateTraceID updated to import from pkg/observability
directly (no longer go through gateway aliases).

pkg/gateway/proxy.go and pkg/gateway/certs.go shrink to type aliases +
forwarder functions so external callers (cmd/gateway/main.go and any
historical importers) continue to compile.

cmd/gateway/main.go migrated to import pkg/edge directly — edge is the
canonical home now. The gateway aliases stay in place for safety.

Test sweep green except the same pre-existing pkg/platform/store
testcontainers/Docker failure that's been failing on every PR in this
branch (Docker not running on this machine; reproduces on origin/main).

Closes #45

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Viridian-Inc Viridian-Inc merged commit 4513e01 into main May 2, 2026
5 checks passed
@Viridian-Inc Viridian-Inc deleted the chore/extract-edge-package branch May 2, 2026 09:45
Viridian-Inc added a commit that referenced this pull request May 2, 2026
Last remaining brand-leak in non-test Go: tools/cloudmock-dns owned the
helper that reads domain config from a Pulumi YAML, with the field name
"Autotend" even when the value defaulted to cloudmock.app. Rename to
Primary to match the rest of the codebase post-#36/#38/#42/#46.

- domainConfig.Autotend → Primary; all call sites updated.
- parsePulumiConfig accepts "primary" as the canonical YAML key, falls
  back to "autotend" for backwards compat with existing autotend-infra
  Pulumi configs that still pass that key.
- sortedDomains pair key updated from "cloudmock" (which was duplicated
  for both rows) to "primary" for the primary entry.
- Three new test cases:
  - TestParsePulumiConfig_LegacyAutotendKey — verifies the alias works.
  - TestParsePulumiConfig_PrimaryWinsOverLegacy — verifies precedence
    when both are set.
  - Existing TestParsePulumiConfig updated to use the new "primary" key.

The remaining "autotend" mentions in non-test Go (a parser example
comment in pkg/iac and the alias-justification comment in
pkg/gateway/proxy.go) are accurate descriptive context for historical
input shapes / importers — left as-is.

Closes #49

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

Phase 2: extract reverse proxy from pkg/gateway into pkg/edge

1 participant