mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 19:00:54 -06:00
OAuth: Support pagination for GitHub orgs (#58648)
* Support pagination for github orgs * fix unused variable * Increase initial page to 100 per the way teams work
This commit is contained in:
parent
fa9f1c3a52
commit
4de0149bd9
@ -147,27 +147,33 @@ func (s *SocialGithub) HasMoreRecords(headers http.Header) (string, bool) {
|
||||
}
|
||||
|
||||
func (s *SocialGithub) FetchOrganizations(client *http.Client, organizationsUrl string) ([]string, error) {
|
||||
url := organizationsUrl
|
||||
hasMore := true
|
||||
logins := make([]string, 0)
|
||||
|
||||
type Record struct {
|
||||
Login string `json:"login"`
|
||||
}
|
||||
|
||||
response, err := s.httpGet(client, organizationsUrl)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting organizations: %s", err)
|
||||
for hasMore {
|
||||
response, err := s.httpGet(client, url)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting organizations: %s", err)
|
||||
}
|
||||
|
||||
var records []Record
|
||||
|
||||
err = json.Unmarshal(response.Body, &records)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting organizations: %s", err)
|
||||
}
|
||||
|
||||
for _, record := range records {
|
||||
logins = append(logins, record.Login)
|
||||
}
|
||||
|
||||
url, hasMore = s.HasMoreRecords(response.Headers)
|
||||
}
|
||||
|
||||
var records []Record
|
||||
|
||||
err = json.Unmarshal(response.Body, &records)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting organizations: %s", err)
|
||||
}
|
||||
|
||||
var logins = make([]string, len(records))
|
||||
for i, record := range records {
|
||||
logins[i] = record.Login
|
||||
}
|
||||
|
||||
return logins, nil
|
||||
}
|
||||
|
||||
@ -218,7 +224,7 @@ func (s *SocialGithub) UserInfo(client *http.Client, token *oauth2.Token) (*Basi
|
||||
userInfo.Name = data.Name
|
||||
}
|
||||
|
||||
organizationsUrl := fmt.Sprintf(s.apiUrl + "/orgs")
|
||||
organizationsUrl := fmt.Sprintf(s.apiUrl + "/orgs?per_page=100")
|
||||
|
||||
if !s.IsTeamMember(client) {
|
||||
return nil, ErrMissingTeamMembership
|
||||
|
Loading…
Reference in New Issue
Block a user