Skip to content

Commit

Permalink
Limit bindings to max 10
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekMichali committed Oct 11, 2024
1 parent 169babe commit aed2188
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/broker/bind_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ func (b *BindEndpoint) Bind(ctx context.Context, instanceID, bindingID string, d
}
}

bindingList, err := b.bindingsStorage.ListByInstanceID(instanceID)
switch {
case dberr.IsNotFound(err):
return domain.Binding{}, apiresponses.ErrInstanceDoesNotExist
case err != nil:
return domain.Binding{}, apiresponses.NewFailureResponse(fmt.Errorf("failed to get bindings for instance %s", instanceID), http.StatusInternalServerError, fmt.Sprintf("failed to get bindings for instance %s", instanceID))
}

bindingCount := len(bindingList)
// dont forget expired bindings, talk with WW
if bindingCount >= 10 {
message := fmt.Sprintf("maximum number of bindings reached: %d", bindingCount)
return domain.Binding{}, apiresponses.NewFailureResponse(fmt.Errorf(message), http.StatusBadRequest, message)
}

expirationSeconds := b.config.ExpirationSeconds
if parameters.ExpirationSeconds != 0 {
if parameters.ExpirationSeconds > b.config.MaxExpirationSeconds {
Expand Down

0 comments on commit aed2188

Please sign in to comment.