From 98dcf286ff5b9fe126cb2bee1e830146355c13b0 Mon Sep 17 00:00:00 2001 From: zzxwill Date: Wed, 26 Aug 2020 16:17:12 +0800 Subject: [PATCH] API request parameter check for trait attach check parameter `staging` before converting it to bool and add logs --- pkg/oam/trait.go | 12 +++++++----- pkg/server/handler/traitHandler.go | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/oam/trait.go b/pkg/oam/trait.go index 8d3e1403c..d78424489 100644 --- a/pkg/oam/trait.go +++ b/pkg/oam/trait.go @@ -240,18 +240,20 @@ func AttachTrait(c *gin.Context, body apis.TraitBody) (string, error) { for _, f := range body.Flags { fs.String(f.Name, f.Value, "") } - staging, err := strconv.ParseBool(body.Staging) - if err != nil { - return "", err + var staging = false + var err error + if body.Staging != "" { + staging, err = strconv.ParseBool(body.Staging) + if err != nil { + return "", err + } } traitAlias := body.Name template, err := plugins.GetInstalledCapabilityWithCapAlias(types.TypeTrait, traitAlias) if err != nil { return "", err } - appObj, err = AddOrUpdateTrait(body.EnvName, body.AppGroup, body.WorkloadName, fs, template) - if err != nil { return "", err } diff --git a/pkg/server/handler/traitHandler.go b/pkg/server/handler/traitHandler.go index 5cf5e0e13..f1d297f42 100644 --- a/pkg/server/handler/traitHandler.go +++ b/pkg/server/handler/traitHandler.go @@ -8,6 +8,7 @@ import ( "github.com/cloud-native-application/rudrx/pkg/server/apis" "github.com/cloud-native-application/rudrx/pkg/server/util" "github.com/gin-gonic/gin" + ctrl "sigs.k8s.io/controller-runtime" ) // Trait related handlers @@ -19,6 +20,7 @@ func AttachTrait(c *gin.Context) { util.HandleError(c, util.InvalidArgument, "the trait attach request body is invalid") return } + ctrl.Log.Info("request parameters body:", "body", body) msg, err := oam.AttachTrait(c, body) if err != nil { util.HandleError(c, util.StatusInternalServerError, err.Error())