From 2c9f2d56731b69ed4052c4f6e69e46dc878f8d2b Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Mon, 3 Aug 2015 15:47:30 -0600 Subject: [PATCH 1/2] fix bug #488 --- builtin/credential/github/path_login.go | 52 ++++++++++++++++++------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/builtin/credential/github/path_login.go b/builtin/credential/github/path_login.go index 8c4e7ce9f6..be9eb6b251 100644 --- a/builtin/credential/github/path_login.go +++ b/builtin/credential/github/path_login.go @@ -47,12 +47,25 @@ func (b *backend) pathLogin( // Verify that the user is part of the organization var org *github.Organization - orgs, _, err := client.Organizations.List("", nil) - if err != nil { - return nil, err + + orgOpt := &github.ListOptions{ + PerPage: 100, } - for _, o := range orgs { + var allOrgs []github.Organization + for { + orgs, resp, err := client.Organizations.List("", orgOpt) + if err != nil { + return nil, err + } + allOrgs = append(allOrgs, orgs...) + if resp.NextPage == 0 { + break + } + orgOpt.Page = resp.NextPage + } + + for _, o := range allOrgs { if *o.Login == config.Org { org = &o break @@ -64,24 +77,35 @@ func (b *backend) pathLogin( // Get the teams that this user is part of to determine the policies var teamNames []string - teams, _, err := client.Organizations.ListUserTeams(nil) - if err != nil { - return nil, err + + teamOpt := &github.ListOptions{ + PerPage: 100, } - for _, t := range teams { + + var allTeams []github.Team + for { + teams, resp, err := client.Organizations.ListUserTeams(teamOpt) + if err != nil { + return nil, err + } + allTeams = append(allTeams, teams...) + if resp.NextPage == 0 { + break + } + teamOpt.Page = resp.NextPage + } + + for _, t := range allTeams { // We only care about teams that are part of the organization we use if *t.Organization.ID != *org.ID { continue } - // Append the names AND slug so we can get the policies - // Slug is needed for teamnames with whitespaces + // Append the names so we can get the policies teamNames = append(teamNames, *t.Name) - if *t.Name != *t.Slug { - teamNames = append(teamNames, *t.Slug) - } } + policiesList, err := b.Map.Policies(req.Storage, teamNames...) if err != nil { return nil, err @@ -98,3 +122,5 @@ func (b *backend) pathLogin( }, }, nil } + + From 5ca2816084f49d9ef927346eb128db4abade573b Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Mon, 3 Aug 2015 16:34:24 -0600 Subject: [PATCH 2/2] remove newline --- builtin/credential/github/path_login.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/builtin/credential/github/path_login.go b/builtin/credential/github/path_login.go index be9eb6b251..55150b041c 100644 --- a/builtin/credential/github/path_login.go +++ b/builtin/credential/github/path_login.go @@ -122,5 +122,3 @@ func (b *backend) pathLogin( }, }, nil } - -