Skip to content

Commit

Permalink
[scd] check subscription version is present and correct when deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick committed Jan 11, 2024
1 parent 095ca48 commit cd96c47
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/scd/subscriptions_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,13 @@ func (a *Server) DeleteSubscription(ctx context.Context, req *restapi.DeleteSubs
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}

// Retrieve Subscription Version
version := scdmodels.OVN(req.Version)
if version == "" {
return restapi.DeleteSubscriptionResponseSet{Response400: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Missing version"))}}
}

// Retrieve ID of client making call
if req.Auth.ClientID == nil {
return restapi.DeleteSubscriptionResponseSet{Response403: &restapi.ErrorResponse{
Expand All @@ -493,6 +500,8 @@ func (a *Server) DeleteSubscription(ctx context.Context, req *restapi.DeleteSubs
return stacktrace.Propagate(
stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Subscription is owned by different client"),
"Subscription owned by %s, but %s attempted to delete", old.Manager, *req.Auth.ClientID)
case old.Version != version:
return stacktrace.NewErrorWithCode(dsserr.VersionMismatch, "Subscription version %s is not current", version)
}

// Get dependent Operations
Expand Down Expand Up @@ -537,6 +546,8 @@ func (a *Server) DeleteSubscription(ctx context.Context, req *restapi.DeleteSubs
return restapi.DeleteSubscriptionResponseSet{Response400: errResp}
case dsserr.NotFound:
return restapi.DeleteSubscriptionResponseSet{Response404: errResp}
case dsserr.VersionMismatch:
return restapi.DeleteSubscriptionResponseSet{Response409: errResp}
default:
return restapi.DeleteSubscriptionResponseSet{Response500: &api.InternalServerErrorBody{
ErrorMessage: *dsserr.Handle(ctx, stacktrace.Propagate(err, "Got an unexpected error"))}}
Expand Down

0 comments on commit cd96c47

Please sign in to comment.