Skip to content

Commit

Permalink
[scd] oir deletion now checks for OVN correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick committed Aug 28, 2024
1 parent 06a9756 commit e4be985
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions pkg/scd/operational_intents_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"))}}
Expand Down

0 comments on commit e4be985

Please sign in to comment.