diff --git a/pkg/client/factory.go b/pkg/client/factory.go index 064d2b1..6042488 100644 --- a/pkg/client/factory.go +++ b/pkg/client/factory.go @@ -160,16 +160,18 @@ func (p *Factory) TableAdminClientForWatch(ctx *types.APIRequest, s *types.APISc } func setupConfig(ctx *types.APIRequest, cfg *rest.Config, impersonate bool) (*rest.Config, error) { + cfg = rest.CopyConfig(cfg) if impersonate { user, ok := request.UserFrom(ctx.Context()) if !ok { return nil, fmt.Errorf("user not found for impersonation") } - cfg = rest.CopyConfig(cfg) cfg.Impersonate.UserName = user.GetName() cfg.Impersonate.Groups = user.GetGroups() cfg.Impersonate.Extra = user.GetExtra() } + + cfg.WarningHandler = APIWarnings{ctx.Response} return cfg, nil } diff --git a/pkg/client/warn_panda.go b/pkg/client/warn_panda.go new file mode 100644 index 0000000..11639c9 --- /dev/null +++ b/pkg/client/warn_panda.go @@ -0,0 +1,17 @@ +package client + +import ( + "fmt" + "net/http" + + "github.com/sirupsen/logrus" +) + +type APIWarnings struct { + response http.ResponseWriter +} + +func (am APIWarnings) HandleWarningHeader(code int, agent string, message string) { + logrus.Infof("====HandleWarningHeader===== %s", message) + am.response.Header().Add("X-API-Warnings", fmt.Sprintf("%d - %s", code, message)) +}