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)