Skip to content

Commit e6fd4ee

Browse files
committed
Fix lint and regenerate swagger docs
- Extract detectApplicationError into separate method to reduce cyclomatic complexity of logAuditEvent (gocyclo > 15) - Fix gci import formatting in config.go - Regenerate swagger docs for new DetectApplicationErrors config field Signed-off-by: Guillermo Gomez <guillermogomezmora@gmail.com>
1 parent f6a98dd commit e6fd4ee

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

docs/server/docs.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/server/swagger.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/server/swagger.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/audit/auditor.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,25 @@ func (*Auditor) determineOutcome(statusCode int) string {
388388
}
389389
}
390390

391+
// detectApplicationError inspects the captured response body prefix for a
392+
// JSON-RPC error field. It reuses rw.body when IncludeResponseData is
393+
// enabled to avoid double-buffering.
394+
func (*Auditor) detectApplicationError(rw *responseWriter) *mcp.ParsedMCPResponse {
395+
var prefix []byte
396+
if rw.body != nil && rw.body.Len() > 0 {
397+
prefix = rw.body.Bytes()
398+
if len(prefix) > errorDetectionBufferSize {
399+
prefix = prefix[:errorDetectionBufferSize]
400+
}
401+
} else if rw.errorDetectionBody != nil && rw.errorDetectionBody.Len() > 0 {
402+
prefix = rw.errorDetectionBody.Bytes()
403+
}
404+
if len(prefix) > 0 && prefix[0] == '{' {
405+
return mcp.ParseMCPResponse(prefix)
406+
}
407+
return nil
408+
}
409+
391410
// extractSource extracts source information from the HTTP request.
392411
func (a *Auditor) extractSource(r *http.Request) EventSource {
393412
// Get the client IP address

pkg/audit/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func DefaultConfig() *Config {
7878
return &Config{
7979
// Note, these defaults are also present on the kubebuilder annotations above.
8080
// If you change these defaults, you must also change the kubebuilder annotations.
81-
IncludeRequestData: false, // Disabled by default for privacy
82-
IncludeResponseData: false, // Disabled by default for privacy
83-
MaxDataSize: 1024, // 1KB default limit
81+
IncludeRequestData: false, // Disabled by default for privacy
82+
IncludeResponseData: false, // Disabled by default for privacy
83+
MaxDataSize: 1024, // 1KB default limit
8484
DetectApplicationErrors: &detectErrors, // Enabled by default to surface JSON-RPC errors
8585
}
8686
}

0 commit comments

Comments
 (0)