diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go index 4f6bc3d7a..6837eb4fe 100644 --- a/pkg/errors/errors.go +++ b/pkg/errors/errors.go @@ -27,7 +27,7 @@ const ( // BadRequest is used when a user supplies bad request parameters. BadRequest - // VersionMismatch is used when updating a resource with an old version. + // VersionMismatch is used when updating or deleting a resource with an old or incorrect version. VersionMismatch // NotFound is used when looking up a resource that doesn't exist. diff --git a/pkg/scd/operational_intents_handler.go b/pkg/scd/operational_intents_handler.go index 4679d59cb..4886bf8d0 100644 --- a/pkg/scd/operational_intents_handler.go +++ b/pkg/scd/operational_intents_handler.go @@ -39,6 +39,13 @@ func (a *Server) DeleteOperationalIntentReference(ctx context.Context, req *rest Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Missing manager"))}} } + // Retrieve OVN + ovn := scdmodels.OVN(req.Ovn) + if ovn == "" { + return restapi.DeleteOperationalIntentReferenceResponseSet{Response400: &restapi.ErrorResponse{ + Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Missing OVN"))}} + } + var response *restapi.ChangeOperationalIntentReferenceResponse action := func(ctx context.Context, r repos.Repository) (err error) { // Get OperationalIntent to delete @@ -56,6 +63,11 @@ func (a *Server) DeleteOperationalIntentReference(ctx context.Context, req *rest "OperationalIntent owned by %s, but %s attempted to delete", old.Manager, *req.Auth.ClientID) } + if old.OVN != ovn { + return stacktrace.NewErrorWithCode(dsserr.VersionMismatch, + "Current version is %s but client specified version %s", old.OVN, ovn) + } + // Get the Subscription supporting the OperationalIntent, if one is defined var sub *scdmodels.Subscription removeImplicitSubscription := false @@ -142,6 +154,8 @@ func (a *Server) DeleteOperationalIntentReference(ctx context.Context, req *rest return restapi.DeleteOperationalIntentReferenceResponseSet{Response403: errResp} case dsserr.NotFound: return restapi.DeleteOperationalIntentReferenceResponseSet{Response404: errResp} + case dsserr.VersionMismatch: + return restapi.DeleteOperationalIntentReferenceResponseSet{Response409: errResp} default: return restapi.DeleteOperationalIntentReferenceResponseSet{Response500: &api.InternalServerErrorBody{ ErrorMessage: *dsserr.Handle(ctx, stacktrace.Propagate(err, "Got an unexpected error"))}}