mirror of
https://github.com/fleetdm/fleet
synced 2026-05-15 21:18:29 +00:00
For #27287 Video explaining the PR: https://www.youtube.com/watch?v=ZHgFUAvrPEI This PR adds SCIM Users support for Okta. The goal is to first add Users/Groups support so that the remaining backend SCIM work can be done in parallel. This PR does not include the following, which will be added in later PRs - Changes file - Groups support for Okta - Full support for Entra ID - Integration tests # Checklist for submitter - [x] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [x] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [x] Added/updated automated tests - [x] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [x] Manual QA for all new/changed functionality
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package log
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/contexts/logging"
|
|
"github.com/go-kit/kit/endpoint"
|
|
kitlog "github.com/go-kit/log"
|
|
)
|
|
|
|
// Logged wraps an endpoint and adds the error if the context supports it
|
|
func Logged(next endpoint.Endpoint) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
|
|
res, err := next(ctx, request)
|
|
if err != nil {
|
|
logging.WithErr(ctx, err)
|
|
return nil, err
|
|
}
|
|
if errResp, ok := res.(interface{ Error() error }); ok {
|
|
err = errResp.Error()
|
|
if err != nil {
|
|
logging.WithErr(ctx, err)
|
|
}
|
|
}
|
|
return res, nil
|
|
}
|
|
}
|
|
|
|
func LogRequestEnd(logger kitlog.Logger) func(context.Context, http.ResponseWriter) context.Context {
|
|
return func(ctx context.Context, w http.ResponseWriter) context.Context {
|
|
logCtx, ok := logging.FromContext(ctx)
|
|
if !ok {
|
|
return ctx
|
|
}
|
|
logCtx.Log(ctx, logger)
|
|
return ctx
|
|
}
|
|
}
|
|
|
|
func LogResponseEndMiddleware(logger kitlog.Logger, next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
next.ServeHTTP(w, r)
|
|
LogRequestEnd(logger)(r.Context(), w)
|
|
})
|
|
}
|