Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Prevent infinite pagination loop
Browse files Browse the repository at this point in the history
  • Loading branch information
palourde committed Apr 14, 2016
1 parent 798c48c commit a6950ce
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion uchiwa/sensu/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func (api *API) getSlice(endpoint string, limit int) ([]interface{}, error) {
if err != nil {
return nil, fmt.Errorf("Could not parse the JSON-encoded response body: %v", err)
}

// Verify if the endpoint supports pagination
if limit != -1 && res.Header.Get("X-Pagination") != "" {
var xPagination structs.XPagination
Expand All @@ -74,6 +73,11 @@ func (api *API) getSlice(endpoint string, limit int) ([]interface{}, error) {
return nil, fmt.Errorf("Could not parse the JSON-encoded response body: %v", err)
}

if len(partialList) == 0 {
logger.Debugf("No additional elements found, exiting pagination for %s endpoint", endpoint)
break
}

for _, e := range partialList {
list = append(list, e)
}
Expand Down

0 comments on commit a6950ce

Please sign in to comment.