Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass error callback function to auditing http filter. #606

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/metal-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,14 @@ func initRestServices(audit auditing.Auditing, withauth bool, ipmiSuperUser meta
}

if audit != nil {
httpFilter, err := auditing.HttpFilter(audit, logger.WithGroup("audit-middleware"))
filterOpt := auditing.NewHttpFilterErrorCallback(func(err error, response *restful.Response) {
httperr := httperrors.InternalServerError(err)
if err := response.WriteHeaderAndEntity(httperr.StatusCode, httperr); err != nil {
logger.Error("failed to send response", "error", err)
}
})

httpFilter, err := auditing.HttpFilter(audit, logger.WithGroup("audit-middleware"), filterOpt)
if err != nil {
log.Fatalf("unable to create http filter for auditing: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/looplab/fsm v1.0.2
github.com/metal-stack/go-ipam v1.14.8
github.com/metal-stack/masterdata-api v0.11.5
github.com/metal-stack/metal-lib v0.19.0
github.com/metal-stack/metal-lib v0.19.1-0.20250203130132-879b43f148f1
github.com/metal-stack/security v0.9.1
github.com/metal-stack/v v1.0.3
github.com/nsqio/go-nsq v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ github.com/metal-stack/go-ipam v1.14.8 h1:M840hp1RcM2fHfMjFG5rn02yKFq6hXh+WvmYIS
github.com/metal-stack/go-ipam v1.14.8/go.mod h1:LzAKT0X9dGAMs1uoLyJfJZkhwMMDLaSYvx9n6MJ9FI4=
github.com/metal-stack/masterdata-api v0.11.5 h1:r7bYdhdVgOjCk6k7K/SCLlHALH23ZuMGY8E4udk4wXQ=
github.com/metal-stack/masterdata-api v0.11.5/go.mod h1:Xk8kqxAp3NkAc2BX8yTIWgSlD77T897QSdRSluWvP4w=
github.com/metal-stack/metal-lib v0.19.0 h1:4yBnp/jPGgX9KeCje3A4MFL2oDjgjOjgsIK391LltRI=
github.com/metal-stack/metal-lib v0.19.0/go.mod h1:fCMaWwVGA/xAoGvBk72/nfzqBkHly0iOzrWpc55Fau4=
github.com/metal-stack/metal-lib v0.19.1-0.20250203130132-879b43f148f1 h1:c/P0oUzOXu7bAENmpNRKuFFPNa9KFCaQzkDi99dCex8=
github.com/metal-stack/metal-lib v0.19.1-0.20250203130132-879b43f148f1/go.mod h1:fCMaWwVGA/xAoGvBk72/nfzqBkHly0iOzrWpc55Fau4=
github.com/metal-stack/security v0.9.1 h1:cx3afSJPSOh03E9gKjdG6mbNU+ox/dqV7q8T9MkrHxo=
github.com/metal-stack/security v0.9.1/go.mod h1:ENm5kPjqh4uYvn79sAIxd6GZBwtF2GSsGdkLELrB/D4=
github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs=
Expand Down
Loading