Skip to content
New issue

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

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

Already on GitHub? # to your account

GitHub Pagination #1804

Merged
merged 1 commit into from
Mar 22, 2018
Merged

GitHub Pagination #1804

merged 1 commit into from
Mar 22, 2018

Conversation

russjones
Copy link
Contributor

Purpose

Teleport was only returning the first page of results when querying the GET /user/teams endpoint. This results in a Unable to process callback from Github error for users with more than 30 teams.

Implementation

When processing the response to a GET request, extract any pagination links from the response header. Use the next link to paginate over all teams and return the full result set.

Related Issues

Fixes #1734

@russjones russjones requested review from r0mant and klizhentas March 21, 2018 22:11
@russjones russjones force-pushed the rjones/web-linking branch from 8a9a318 to 5265384 Compare March 21, 2018 22:12
Copy link
Contributor

@klizhentas klizhentas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have a couple of comments, otherwise lgtm

@@ -274,6 +274,8 @@ func populateGithubClaims(client githubAPIClientI) (*services.GithubClaims, erro
if err != nil {
return nil, trace.Wrap(err, "failed to query Github user teams")
}
log.Debugf("Retrieved %v teams for GitHub user %v", len(teams), user.Login)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing dot. Also you can use structured logging to list teams:

log.WithFields(log.Fields{"teams:" teams, "user": user.Login})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full list of teams is printed a few lines below. I added this line as a quick sanity check when we are debugging things for customers. For example maybe pagination breaks at some point in the future, this is a good diagnostic line to tell at a glance something is wrong.


// If the response returned a next page link, continue following the next
// page links until all teams have been retrieved.
for nextPage != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you limit the number of pages to some reasonably high number? E.g. if github API goes crazy and will start returning circular link, this logic will hang forever.

@russjones russjones force-pushed the rjones/web-linking branch from 5265384 to 1a62aca Compare March 21, 2018 23:16
@russjones russjones force-pushed the rjones/web-linking branch from 1a62aca to e06521d Compare March 21, 2018 23:58
@russjones russjones merged commit df40705 into master Mar 22, 2018
@russjones russjones deleted the rjones/web-linking branch March 22, 2018 00:06
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants