diff --git a/handlers/transaction.go b/handlers/transaction.go index 94b66728..7c4ef044 100644 --- a/handlers/transaction.go +++ b/handlers/transaction.go @@ -24,6 +24,7 @@ import ( "github.com/haproxytech/dataplaneapi/haproxy" "github.com/haproxytech/dataplaneapi/misc" "github.com/haproxytech/dataplaneapi/operations/transactions" + log "github.com/sirupsen/logrus" "github.com/haproxytech/dataplaneapi/rate" ) @@ -128,6 +129,12 @@ func (th *CommitTransactionHandlerImpl) Handle(params transactions.CommitTransac if *params.ForceReload { err := th.ReloadAgent.ForceReload() if err != nil { + if *params.EnableRevert { + var errR error + if errR = th.Client.Configuration.RevertTransaction(t); errR != nil { + log.Debug("revert fail", errR) + } + } e := misc.HandleError(err) return transactions.NewCommitTransactionDefault(int(*e.Code)).WithPayload(e) } diff --git a/operations/transactions/commit_transaction_parameters.go b/operations/transactions/commit_transaction_parameters.go index 556e79bd..c9c6b70a 100644 --- a/operations/transactions/commit_transaction_parameters.go +++ b/operations/transactions/commit_transaction_parameters.go @@ -37,11 +37,13 @@ func NewCommitTransactionParams() CommitTransactionParams { var ( // initialize parameters with default values - forceReloadDefault = bool(false) + forceReloadDefault = bool(false) + enableReverseDefault = bool(false) ) return CommitTransactionParams{ - ForceReload: &forceReloadDefault, + ForceReload: &forceReloadDefault, + EnableRevert: &enableReverseDefault, } } @@ -59,6 +61,8 @@ type CommitTransactionParams struct { Default: false */ ForceReload *bool + + EnableRevert *bool /*Transaction id Required: true In: path @@ -82,6 +86,11 @@ func (o *CommitTransactionParams) BindRequest(r *http.Request, route *middleware res = append(res, err) } + qEnableRevert, qhkEnableRevert, _ := qs.GetOK("enable_revert") + if err := o.bindEnableRevert(qEnableRevert, qhkEnableRevert, route.Formats); err != nil { + res = append(res, err) + } + rID, rhkID, _ := route.Params.GetOK("id") if err := o.bindID(rID, rhkID, route.Formats); err != nil { res = append(res, err) @@ -116,6 +125,29 @@ func (o *CommitTransactionParams) bindForceReload(rawData []string, hasKey bool, return nil } +// bindEnableRevert binds and validates parameter EnableRevert from query. +func (o *CommitTransactionParams) bindEnableRevert(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewCommitTransactionParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("enable_revert", "query", "bool", raw) + } + o.EnableRevert = &value + + return nil +} + // bindID binds and validates parameter ID from path. func (o *CommitTransactionParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { var raw string