diff --git a/.golangci.yaml b/.golangci.yaml index a9dd7d49..e5713c17 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,6 +1,5 @@ run: concurrency: 4 - deadline: 10m linters: disable: - musttag @@ -11,4 +10,4 @@ linters: presets: - bugs - unused -fast: true + fast: true diff --git a/cmd/metal-api/internal/service/audit-service.go b/cmd/metal-api/internal/service/audit-service.go index 87bc0212..07d03c60 100644 --- a/cmd/metal-api/internal/service/audit-service.go +++ b/cmd/metal-api/internal/service/audit-service.go @@ -64,7 +64,7 @@ func (r *auditResource) find(request *restful.Request, response *restful.Respons return } - backendResult, err := r.a.Search(auditing.EntryFilter{ + backendResult, err := r.a.Search(request.Request.Context(), auditing.EntryFilter{ Limit: requestPayload.Limit, From: requestPayload.From, To: requestPayload.To, @@ -73,6 +73,7 @@ func (r *auditResource) find(request *restful.Request, response *restful.Respons Type: auditing.EntryType(requestPayload.Type), User: requestPayload.User, Tenant: requestPayload.Tenant, + Project: requestPayload.Project, Detail: auditing.EntryDetail(requestPayload.Detail), Phase: auditing.EntryPhase(requestPayload.Phase), Path: requestPayload.Path, diff --git a/cmd/metal-api/internal/service/v1/audit.go b/cmd/metal-api/internal/service/v1/audit.go index aa5f2d07..060b415f 100644 --- a/cmd/metal-api/internal/service/v1/audit.go +++ b/cmd/metal-api/internal/service/v1/audit.go @@ -18,8 +18,9 @@ type AuditFindRequest struct { RequestId string `json:"rqid" optional:"true"` Type string `json:"type" optional:"true"` - User string `json:"user" optional:"true"` - Tenant string `json:"tenant" optional:"true"` + User string `json:"user" optional:"true"` + Tenant string `json:"tenant" optional:"true"` + Project string `json:"project" optional:"true"` Detail string `json:"detail" optional:"true"` Phase string `json:"phase" optional:"true"` diff --git a/cmd/metal-api/main.go b/cmd/metal-api/main.go index 31514a80..77f9e9c2 100644 --- a/cmd/metal-api/main.go +++ b/cmd/metal-api/main.go @@ -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) } @@ -915,16 +922,16 @@ func createAuditingClient(log *slog.Logger) (auditing.Auditing, error) { return nil, nil } - c := auditing.Config{ - Component: "metal-api", + return auditing.NewMeilisearch(auditing.Config{ + Component: "metal-api", + Log: log, + }, auditing.MeilisearchConfig{ URL: viper.GetString("auditing-url"), APIKey: viper.GetString("auditing-api-key"), IndexPrefix: viper.GetString("auditing-index-prefix"), RotationInterval: auditing.Interval(viper.GetString("auditing-index-interval")), Keep: viper.GetInt64("auditing-keep"), - Log: log, //FIXME - } - return auditing.New(c) + }) } func run() error { diff --git a/go.mod b/go.mod index 3ffbd58f..dd3c446b 100644 --- a/go.mod +++ b/go.mod @@ -20,8 +20,8 @@ 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/security v0.9.1 + github.com/metal-stack/metal-lib v0.20.1 + github.com/metal-stack/security v0.9.3 github.com/metal-stack/v v1.0.3 github.com/nsqio/go-nsq v1.1.0 github.com/prometheus/client_golang v1.20.5 @@ -110,6 +110,7 @@ require ( github.com/lestrrat-go/jwx/v2 v2.1.3 // indirect github.com/lestrrat-go/option v1.0.1 // indirect github.com/lib/pq v1.10.9 // indirect + github.com/lopezator/migrator v0.3.1 // indirect github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect github.com/magiconair/properties v1.8.9 // indirect github.com/mailru/easyjson v0.9.0 // indirect diff --git a/go.sum b/go.sum index 755d726d..38974218 100644 --- a/go.sum +++ b/go.sum @@ -174,10 +174,22 @@ github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0 h1:nHoRIX8iXob3Y2kdt9Ksj github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0/go.mod h1:c1tRKs5Tx7E2+uHGSyyncziFjvGpgv4H2HrqXeUQ/Uk= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= +github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/pgconn v1.11.0 h1:HiHArx4yFbwl91X3qqIHtUFoiIfLNJXCQRsnzkiwwaQ= +github.com/jackc/pgconn v1.11.0/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI= +github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= +github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgproto3/v2 v2.2.0 h1:r7JypeP2D3onoQTCxWdTpCtJ4D+qpKr0TxvoyMhZ5ns= +github.com/jackc/pgproto3/v2 v2.2.0/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgtype v1.10.0 h1:ILnBWrRMSXGczYvmkYD6PsYyVFUNLTnIUJHHDLmqk38= +github.com/jackc/pgtype v1.10.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgx/v4 v4.15.0 h1:B7dTkXsdILD3MF987WGGCcg+tvLW6bZJdEcqVFeU//w= +github.com/jackc/pgx/v4 v4.15.0/go.mod h1:D/zyOyXiaM1TmVWnOM18p0xdDtdakRBa0RsVGI3U3bw= github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= @@ -233,6 +245,8 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/looplab/fsm v1.0.2 h1:f0kdMzr4CRpXtaKKRUxwLYJ7PirTdwrtNumeLN+mDx8= github.com/looplab/fsm v1.0.2/go.mod h1:PmD3fFvQEIsjMEfvZdrCDZ6y8VwKTwWNjlpEr6IKPO4= +github.com/lopezator/migrator v0.3.1 h1:ZFPT6aC7+nGWkqhleynABZ6ftycSf6hmHHLOaryq1Og= +github.com/lopezator/migrator v0.3.1/go.mod h1:X+lHDMZ9Ci3/KdbypJcQYFFwipVrJsX4fRCQ4QLauYk= github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0= github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k= github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM= @@ -257,10 +271,10 @@ 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/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/metal-lib v0.20.1 h1:gxNg512dS5yzDebELtPZjmoWond0Gw0HHEkSVIAOWRE= +github.com/metal-stack/metal-lib v0.20.1/go.mod h1:zYzXYpNA4nQ+ANx19s/+1Yb/Q6xhS1nQK2yK2/ryXZM= +github.com/metal-stack/security v0.9.3 h1:ZF5rGeZ4fIFe0DFFQWkXsUDCzODyjdrpvKmeaLOz9lo= +github.com/metal-stack/security v0.9.3/go.mod h1:ENm5kPjqh4uYvn79sAIxd6GZBwtF2GSsGdkLELrB/D4= github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs= github.com/metal-stack/v v1.0.3/go.mod h1:YTahEu7/ishwpYKnp/VaW/7nf8+PInogkfGwLcGPdXg= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= diff --git a/spec/metal-api.json b/spec/metal-api.json index 02b48536..4cac0587 100644 --- a/spec/metal-api.json +++ b/spec/metal-api.json @@ -469,6 +469,9 @@ "phase": { "type": "string" }, + "project": { + "type": "string" + }, "remote_addr": { "type": "string" },