Skip to content

Commit

Permalink
Merge pull request #226 from kilosonc/feat-mutating-admission-webhook
Browse files Browse the repository at this point in the history
fix: mutating dose not work
  • Loading branch information
kilosonc authored May 7, 2024
2 parents 12cb36e + b781db6 commit 5b40856
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/middleware/admission/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func Middleware(skippers ...middleware.Skipper) gin.HandlerFunc {
rpcerror.ParamError.WithErrMsg(fmt.Sprintf("request body is invalid, err: %v", err)))
return
}
// restore the request body
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
if len(bodyBytes) > 0 {
contentType := c.ContentType()
if contentType == binding.MIMEJSON || contentType == "" {
Expand Down Expand Up @@ -90,6 +88,16 @@ func Middleware(skippers ...middleware.Skipper) gin.HandlerFunc {
rpcerror.ParamError.WithErrMsg(fmt.Sprintf("admission validating failed: %v", err)))
return
}
if admissionRequest.Object != nil {
bodyBytes, err = json.Marshal(admissionRequest.Object)
if err != nil {
response.AbortWithRPCError(c,
rpcerror.ParamError.WithErrMsg(fmt.Sprintf("marshal request body failed, err: %v", err)))
return
}
}
// restore the request body
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
c.Next()
}, skippers...)
}

0 comments on commit 5b40856

Please sign in to comment.