mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-07 20:11:31 +00:00
aaddd31d20
Continuing Phase 9 ARCH-M2 closure. Sprint 6 groups the server-tier
infrastructure structs (the things that configure HOW the server
runs) and the HIGH-12 demo-mode startup-guard helper that exclusively
serves the ServerConfig.Host gate.
What moved
==========
internal/config/server.go (new, 374 lines including BSL header +
Phase 9 doc-comment + 2 imports +
7 structs + 1 unexported helper)
Seven structs:
- ServerConfig (HTTP listener: Host, Port, MaxBodySize,
TLS sub-struct, AuditFlushTimeoutSeconds)
- ServerTLSConfig (HTTPS-only TLS material: CertPath + KeyPath)
- DatabaseConfig (URL + MaxConnections + MigrationsPath +
DemoSeed)
- SchedulerConfig (all 15 scheduler-loop tunables: RenewalCheck,
JobProcessor, RenewalConcurrency, agent-health,
notification-process + retry, retry-interval,
job-timeout, AwaitingCSR + Approval timeouts,
short-lived-expiry, CRL-generation, OCSP-rate-
limit, cert-export-rate-limit, deploy-backup-
retention, K8s-kubelet-sync-timeout)
- LogConfig (Level + Format)
- RateLimitConfig (Enabled + RPS + BurstSize + per-user
overrides)
- CORSConfig (AllowedOrigins — empty deny-by-default)
One unexported helper:
- isLoopbackAddr() (HIGH-12 demo-mode guard: 127.0.0.1, ::1,
and "localhost" return true; 0.0.0.0, ::,
and non-localhost hostnames return false.
Same-package callers: Validate() in config.go
+ isLoopbackAddr_test in config_test.go,
both unaffected by the move.)
Three sed passes (highest line numbers first so positions don't shift)
======================================================================
The edit was performed via three independent sed deletes from
highest-line to lowest-line so each delete's range references the
file's pre-shift line numbers:
1. sed -i '1924,1963d' — deleted isLoopbackAddr (40 lines)
2. sed -i '834,893d' — deleted LogConfig + RateLimitConfig +
CORSConfig (60 lines)
3. sed -i '624,810d' — deleted ServerConfig + ServerTLSConfig +
DatabaseConfig + SchedulerConfig
(187 lines)
Total: 287 lines deleted. Reverse-order matters because each delete
shifts subsequent line numbers; doing them top-down would require
re-deriving every range mid-edit.
Why ApprovalConfig stayed in config.go
=======================================
ApprovalConfig (RBAC-related — issuance-approval workflow) sits
between SchedulerConfig and LogConfig in the original file ordering.
It's NOT server-tier infrastructure — it belongs with the Auth/RBAC
surface. Sprint 6's sed ranges deliberately preserve it where it
lives. Operator may want to fold it into a future Auth-followup cut
if the approval surface needs to live adjacent to AuthConfig.
Import-graph hygiene
====================
isLoopbackAddr was the ONLY user of `net` in config.go (verified via
`grep -nE '\bnet\.' internal/config/config.go` → 2 hits, both inside
isLoopbackAddr's body). After the move, config.go's `net` import
becomes unused — would have failed `go vet`. This commit removes the
`net` line from config.go's import block. server.go imports `net`
directly. The `time` import in config.go stays because the still-
in-place OCSPResponderConfig / DigestConfig / HealthCheckConfig /
NetworkScanConfig / VerificationConfig / per-vendor-issuer configs
all reference `time.Duration`.
Public-surface invariant
========================
Every type, exported field, and doc-comment is byte-identical to
pre-split. Package stays `config`. Every external caller of
`config.ServerConfig` / `config.ServerTLSConfig` / `config.DatabaseConfig`
/ `config.SchedulerConfig` / `config.LogConfig` / `config.RateLimitConfig`
/ `config.CORSConfig` resolves the same way. The unexported
isLoopbackAddr is invisible to external consumers; its same-package
callers (Validate, the test) continue to resolve via the package
symbol table.
Verification (all clean):
gofmt -l internal/config/ → clean
go build ./internal/config/... → clean
go test ./internal/config/... -count=1 → ok (0.68s)
staticcheck ./internal/config/... → clean
go build ./cmd/server/...
./internal/auth/...
./internal/api/router/...
./internal/api/handler/...
./internal/scheduler/... → clean (the critical
broader-importer check)
grep -nE '^type (ServerConfig|ServerTLSConfig|DatabaseConfig|SchedulerConfig|LogConfig|RateLimitConfig|CORSConfig)|^func isLoopbackAddr' internal/config/config.go
→ empty (none remain in config.go)
grep -nE '^type (ServerConfig|ServerTLSConfig|DatabaseConfig|SchedulerConfig|LogConfig|RateLimitConfig|CORSConfig)|^func isLoopbackAddr' internal/config/server.go
→ 7 types + 1 func (correct)
grep -nE '\bnet\.' internal/config/config.go
→ empty (the import-removal was load-bearing)
LOC delta:
config.go: 1963 → 1673 (-290 lines: -287 from three sed cuts,
-1 from import-block
line removal,
-2 from misc gofmt cleanup)
server.go: new, 374 lines (incl. 87-line Phase 9 doc-comment +
BSL header + package decl + 2 imports)
Cumulative Phase 9 progress (Sprints 1+2+3+4+5+6 from config.go):
Pre-Phase-9: 3403 LOC
After Sprint 1 (Notifier): 3335 LOC (-68)
After Sprint 2 (ACME): 3108 LOC (-227)
After Sprint 3 (SCEP): 2774 LOC (-334)
After Sprint 4 (EST): 2467 LOC (-307)
After Sprint 5 (Auth): 1963 LOC (-504)
After Sprint 6 (Server): 1673 LOC (-290)
Total Sprint 1+2+3+4+5+6: -1730 LOC (-50.8%)
Notable milestone: config.go has now lost MORE than HALF its original
lines (-50.8%). One more cut from config.go remains (Sprint 7 ~600
LOC of per-vendor issuer configs) before the file split moves on to
non-config hotspots (Sprints 8-12).
Pattern lesson — import-graph cleanup
======================================
Splits that move the LAST consumer of an import need to remove the
import from the source file or `go vet` / build will fail. The check
is `grep -nE '\bnet\.' internal/config/config.go` (or whichever
package) before commit — if empty, drop the import line. Past
sprints didn't hit this because the moved-out helpers used only
shared packages (`strings`, `os`, `fmt`, `time`) that other code in
config.go still uses. Sprint 6's `net` removal is the first
import-rebalancing in Phase 9.
Three-pass sed pattern (also new in Sprint 6)
=============================================
Prior sprints did one or two sed deletes. Sprint 6 needed three
because the Server-family structs straddled ApprovalConfig and
isLoopbackAddr lived far from the struct block. Doing them
highest-line-first means each range references pre-shift line
numbers — no mid-edit re-derivation required.
Next queued (Sprint 7): Issuers family from config.go →
internal/config/issuers.go (~600 LOC). Includes KeygenConfig +
CAConfig + the ten per-vendor configs (StepCA, Vault, DigiCert,
Sectigo, GoogleCAS, AWSACMPCA, Entrust, GlobalSign, EJBCA, OpenSSL).
This is the LAST config.go cut of Phase 9; after Sprint 7 ships,
config.go should drop to ~1100-1200 LOC and the remaining splits
target non-config hotspots (cmd/server/main.go, service/acme.go,
mcp/tools.go, auth_session_oidc.go, cmd/agent/main.go).
Closes: cowork/certctl-architecture-diligence-audit.html#fix-ARCH-M2
(partial — 6 of 12 — full ARCH-M2 closure is the aggregate)