Skip to content

Commit

Permalink
do not audit if length of commands is 0 (#2063)
Browse files Browse the repository at this point in the history
  • Loading branch information
CraigMChen authored Sep 23, 2021
1 parent f184f42 commit fe4f001
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion modules/cmp/steve/middleware/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ func (a *Auditor) AuditMiddleWare(next http.Handler) http.Handler {
cmd := fmt.Sprintf("%s: %s", cwt.start.Format(time.RFC3339), cwt.cmd)
cmds = append(cmds, cmd)
}
res := strings.Join(cmds, "\n")
if len(cmds) == 0 {
return
}
res := fmt.Sprintf("\n%s", strings.Join(cmds, "\n"))
if len(res) > maxAuditLength {
res = res[:maxAuditLength] + "..."
}
Expand Down
8 changes: 4 additions & 4 deletions modules/cmp/steve/middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func NewAuthenticator(bdl *bundle.Bundle) *Authenticator {
// AuthMiddleware authenticate for steve server by bundle.
func (a *Authenticator) AuthMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
vars := parseVars(req)
ctx := context.WithValue(req.Context(), varsKey, vars)
muxVars := parseVars(req)
ctx := context.WithValue(req.Context(), varsKey, muxVars)
req = req.WithContext(ctx)
clusterName := vars["clusterName"]
typ := vars["type"]
clusterName := muxVars["clusterName"]
typ := muxVars["type"]

userID := req.Header.Get("User-ID")
orgID := req.Header.Get("Org-ID")
Expand Down

0 comments on commit fe4f001

Please sign in to comment.