Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scd] oir deletion now checks for OVN correctness #1082

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 for operational intent to modify"))}}
}

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
Loading