From 705e068a6e5b0daacbc7e495f08feb0322b8cea7 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Wed, 9 Jun 2021 20:08:46 +0800 Subject: [PATCH] fix(common): supported dry run --- pkg/apis/input.go | 4 ++++ pkg/cloudcommon/db/db_dispatcher.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/apis/input.go b/pkg/apis/input.go index c11b4fdc4c..63987deca0 100644 --- a/pkg/apis/input.go +++ b/pkg/apis/input.go @@ -183,6 +183,10 @@ type StandaloneAnonResourceCreateInput struct { // 标签列表,最多支持20个 // example: { "user:rd": "op" } Metadata map[string]string `json:"__meta__" token:"tag" help:"tags in the form of key=value"` + + // 预检验参数,若为true则仅检查参数,并不真正创建变更 + // default: false + DryRun bool `json:"dry_run"` } type StandaloneResourceCreateInput struct { diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index 531b4f783f..a235a0c842 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -1269,6 +1269,15 @@ func _doCreateItem( if err != nil { return nil, httperrors.NewGeneralError(err) } + + dryRun := struct { + DryRun bool + }{} + data.Unmarshal(&dryRun) + if dryRun.DryRun { + return model, nil + } + err = manager.TableSpec().InsertOrUpdate(ctx, model) if err != nil { return nil, httperrors.NewGeneralError(err)