Skip to content

Commit

Permalink
additional logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cjimti committed Sep 4, 2021
1 parent ae690d6 commit 9f7eb96
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions amp.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ func NewApi(cfg *Config) (*Api, error) {

func (a *Api) AdmissionReviewHandler(admissionReview AdmissionReview) gin.HandlerFunc {
return func(c *gin.Context) {
a.Log.Info("AdmissionReview request", zap.Any("type", admissionReview))

rs, err := c.GetRawData()
if err != nil {
a.Log.Error("AdmissionReviewHandler is unable to parse request body",
zap.Error(err),
zap.ByteString("raw_data", rs))
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
"message": "unable to parse request body",
"error": err.Error(),
Expand All @@ -102,6 +107,8 @@ func (a *Api) AdmissionReviewHandler(admissionReview AdmissionReview) gin.Handle
// verify the content type
contentType := c.GetHeader("Content-Type")
if contentType != "application/json" {
a.Log.Error("AdmissionReviewHandler content type expected application/json",
zap.String("content_type", contentType))
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
"error": fmt.Sprintf("contentType=%s, expected application/json", contentType),
})
Expand Down

0 comments on commit 9f7eb96

Please sign in to comment.