API request parameter check for trait attach

check parameter `staging` before converting it
to bool and add logs
This commit is contained in:
zzxwill
2020-08-26 16:17:12 +08:00
parent 3498e5d68a
commit 98dcf286ff
2 changed files with 9 additions and 5 deletions
+7 -5
View File
@@ -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
}
+2
View File
@@ -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())