From 0915eafcc6fba974797ea2e0aa86de795ce61875 Mon Sep 17 00:00:00 2001 From: Julien Perrochet Date: Thu, 29 Aug 2024 17:45:05 +0200 Subject: [PATCH] [scd] oir deletion now checks for OVN correctness (#1082) --- pkg/errors/errors.go | 2 +- pkg/scd/operational_intents_handler.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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..5d8c2ac2d 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 for operational intent to modify"))}} + } + 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"))}}