From 200f59c1d22afbf2a475b676735b34f29099a0ab Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Wed, 18 Sep 2019 07:29:19 +0000 Subject: [PATCH] =?UTF-8?q?validators:=20=E5=BA=94=E5=AF=B9"listener"?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=A2=AB=E9=87=8D=E5=A4=8DValidate=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes e4ef23515f ("aws elb support") --- pkg/cloudcommon/validators/validators.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pkg/cloudcommon/validators/validators.go b/pkg/cloudcommon/validators/validators.go index 3dc2ba42ad..e947cfd257 100644 --- a/pkg/cloudcommon/validators/validators.go +++ b/pkg/cloudcommon/validators/validators.go @@ -383,10 +383,11 @@ func NewNonNegativeValidator(key string) *ValidatorRange { type ValidatorModelIdOrName struct { Validator - ModelKeyword string - OwnerId mcclient.IIdentityProvider - ModelManager db.IModelManager - Model db.IModel + ModelKeyword string + OwnerId mcclient.IIdentityProvider + ModelManager db.IModelManager + Model db.IModel + modelIdKey string noPendingDeleted bool } @@ -459,6 +460,20 @@ func (v *ValidatorModelIdOrName) AllowPendingDeleted(b bool) *ValidatorModelIdOr } func (v *ValidatorModelIdOrName) validate(data *jsonutils.JSONDict) error { + if !data.Contains(v.Key) && data.Contains(v.modelIdKey) { + // a hack when validator is used solely for fetching model + // object. This can happen when input json data was validated + // more than once in different places + j, err := data.Get(v.modelIdKey) + if err != nil { + return err + } + data.Set(v.Key, j) + defer func() { + // restore + data.Remove(v.Key) + }() + } if err, isSet := v.Validator.validateEx(data); err != nil || !isSet { return err }