Skip to content

Commit 24307a0

Browse files
authored
[log] debug: add intermediate logging to GenerateSelfSignedTLS in proxy/tls.go (#3154)
## Summary Adds 3 debug log calls to `GenerateSelfSignedTLS` in `internal/proxy/tls.go` using the existing `logTLS` logger (`logger.New("proxy:tls")`). ## Changes The function already logged at entry and completion. This PR adds intermediate checkpoints: | Step | New Log Call | |------|-------------| | CA cert created | `logTLS.Printf("CA certificate created: serial=%s, notBefore=%s, notAfter=%s", ...)` | | Server cert created | `logTLS.Printf("server certificate created: dnsNames=%v, ipAddresses=%v", ...)` | | PEM files written | `logTLS.Printf("TLS certificate files written: caCert=%s, cert=%s, key=%s", ...)` | | Key pair loaded | `logTLS.Print("TLS key pair loaded successfully")` | ## Why This Helps `GenerateSelfSignedTLS` performs several distinct operations (key generation, cert signing, file I/O, key-pair loading) where any step can fail independently. Without intermediate logging, a failure at "failed to load server cert pair" gives no indication whether the issue is in the key generation, cert creation, or file writing phases. The new logs pinpoint exactly how far the function progressed before failing. ## Logging Guidelines Followed - Reuses existing `logTLS` logger — no duplicate declaration - `Printf` used for structured data (serial, SANs, file paths) - `Print` used for simple state confirmations - No side effects in logger arguments - All values are already computed before the log call - 6 total log calls (3 existing + 3 new) — within the 3–7 recommended range ## Files Changed - `internal/proxy/tls.go` — 5 lines added (3 log calls + 1 newline separation) > Generated by [Go Logger Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/23971566678/agentic_workflow) · [◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+go-logger%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Go Logger Enhancement, engine: copilot, model: auto, id: 23971566678, workflow_id: go-logger, run: https://github.com/github/gh-aw-mcpg/actions/runs/23971566678 --> <!-- gh-aw-workflow-id: go-logger -->
2 parents 1699231 + 9806b3b commit 24307a0

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

internal/proxy/tls.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ func GenerateSelfSignedTLS(dir string) (*TLSConfig, error) {
9898
if err != nil {
9999
return nil, fmt.Errorf("failed to parse CA certificate: %w", err)
100100
}
101+
logTLS.Printf("CA certificate created: serial=%s, notBefore=%s, notAfter=%s",
102+
caSerial.String(), notBefore.Format(time.RFC3339), notAfter.Format(time.RFC3339))
101103

102104
// --- Generate server certificate ---
103105
serverKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
@@ -128,6 +130,7 @@ func GenerateSelfSignedTLS(dir string) (*TLSConfig, error) {
128130
if err != nil {
129131
return nil, fmt.Errorf("failed to create server certificate: %w", err)
130132
}
133+
logTLS.Printf("server certificate created: dnsNames=%v, ipAddresses=%v", serverTemplate.DNSNames, serverTemplate.IPAddresses)
131134

132135
// --- Write files ---
133136
caCertPath := filepath.Join(dir, "ca.crt")
@@ -148,12 +151,14 @@ func GenerateSelfSignedTLS(dir string) (*TLSConfig, error) {
148151
if err := writePEM(keyPath, "EC PRIVATE KEY", serverKeyDER, 0600); err != nil {
149152
return nil, fmt.Errorf("failed to write server key: %w", err)
150153
}
154+
logTLS.Printf("TLS certificate files written: caCert=%s, cert=%s, key=%s", caCertPath, certPath, keyPath)
151155

152156
// --- Build tls.Config ---
153157
serverCertPair, err := tls.LoadX509KeyPair(certPath, keyPath)
154158
if err != nil {
155159
return nil, fmt.Errorf("failed to load server cert pair: %w", err)
156160
}
161+
logTLS.Print("TLS key pair loaded successfully")
157162

158163
tlsCfg := &tls.Config{
159164
Certificates: []tls.Certificate{serverCertPair},

0 commit comments

Comments
 (0)