mirror of
https://github.com/niusmallnan/steve.git
synced 2025-06-22 12:47:04 +00:00
Support warn headers
This commit is contained in:
parent
647cba2be7
commit
a62bf44605
@ -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) {
|
func setupConfig(ctx *types.APIRequest, cfg *rest.Config, impersonate bool) (*rest.Config, error) {
|
||||||
|
cfg = rest.CopyConfig(cfg)
|
||||||
if impersonate {
|
if impersonate {
|
||||||
user, ok := request.UserFrom(ctx.Context())
|
user, ok := request.UserFrom(ctx.Context())
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("user not found for impersonation")
|
return nil, fmt.Errorf("user not found for impersonation")
|
||||||
}
|
}
|
||||||
cfg = rest.CopyConfig(cfg)
|
|
||||||
cfg.Impersonate.UserName = user.GetName()
|
cfg.Impersonate.UserName = user.GetName()
|
||||||
cfg.Impersonate.Groups = user.GetGroups()
|
cfg.Impersonate.Groups = user.GetGroups()
|
||||||
cfg.Impersonate.Extra = user.GetExtra()
|
cfg.Impersonate.Extra = user.GetExtra()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.WarningHandler = APIWarnings{ctx.Response}
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
pkg/client/warn_panda.go
Normal file
17
pkg/client/warn_panda.go
Normal 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))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user