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] cr deletion now checks for OVN correctness #1083

Merged
Merged
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
12 changes: 12 additions & 0 deletions pkg/scd/constraints_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ func (a *Server) DeleteConstraintReference(ctx context.Context, req *restapi.Del
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Missing manager"))}}
}

// Retrieve OVN
ovn := scdmodels.OVN(req.Ovn)
if ovn == "" {
return restapi.DeleteConstraintReferenceResponseSet{Response400: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Missing OVN for constraint to modify"))}}
}

var response *restapi.ChangeConstraintReferenceResponse
action := func(ctx context.Context, r repos.Repository) (err error) {
// Make sure deletion request is valid
Expand All @@ -49,6 +56,9 @@ func (a *Server) DeleteConstraintReference(ctx context.Context, req *restapi.Del
case old.Manager != dssmodels.Manager(*req.Auth.ClientID):
return stacktrace.NewErrorWithCode(dsserr.PermissionDenied,
"Constraint owned by %s, but %s attempted to delete", old.Manager, *req.Auth.ClientID)
case old.OVN != ovn:
return stacktrace.NewErrorWithCode(dsserr.VersionMismatch,
"Current version is %s but client specified version %s", old.OVN, ovn)
}

// Find Subscriptions that may overlap the Constraint's Volume4D
Expand Down Expand Up @@ -106,6 +116,8 @@ func (a *Server) DeleteConstraintReference(ctx context.Context, req *restapi.Del
return restapi.DeleteConstraintReferenceResponseSet{Response400: errResp}
case dsserr.NotFound:
return restapi.DeleteConstraintReferenceResponseSet{Response404: errResp}
case dsserr.VersionMismatch:
return restapi.DeleteConstraintReferenceResponseSet{Response409: errResp}
default:
return restapi.DeleteConstraintReferenceResponseSet{Response500: &api.InternalServerErrorBody{
ErrorMessage: *dsserr.Handle(ctx, stacktrace.Propagate(err, "Got an unexpected error"))}}
Expand Down
Loading