1
0
mirror of https://github.com/niusmallnan/steve.git synced 2025-05-05 14:37:07 +00:00

Support warn headers

This commit is contained in:
niusmallnan 2022-09-13 16:42:59 +08:00
parent 647cba2be7
commit a62bf44605
2 changed files with 20 additions and 1 deletions

View File

@ -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
}

17
pkg/client/warn_panda.go Normal file
View File

@ -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))
}