git.iko.soy/typeable/oauth2-proxy
on master help sign in
github: better debug output for org/team validation
commitc1bf1ad16710659fd5b5763d7cacee30b0121ec2 authorJehiah Czebotar <jehiah@gmail.com> dateFri 24 Jul 2015, 16:10 (11 years ago) parent1e48d89
1 file changed+24−3
providers/github.go+24−3
providers/github.go+24−3
@@ -66,7 +66,7 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
6666
6767 endpoint := "https://api.github.com/user/orgs?" + params.Encode()
6868 req, _ := http.NewRequest("GET", endpoint, nil)
69− req.Header.Set("Accept", "application/vnd.github.moondragon+json")
69+ req.Header.Set("Accept", "application/vnd.github.v3+json")
7070 resp, err := http.DefaultClient.Do(req)
7171 if err != nil {
7272 return false, err
@@ -85,11 +85,16 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
8585 return false, err
8686 }
8787
88+ var presentOrgs []string
8889 for _, org := range orgs {
8990 if p.Org == org.Login {
91+ log.Printf("Found Github Organization: %q", org.Login)
9092 return true, nil
9193 }
94+ presentOrgs = append(presentOrgs, org.Login)
9295 }
96+
97+ log.Printf("Missing Organization:%q in %v", p.Org, presentOrgs)
9398 return false, nil
9499}
95100
@@ -111,7 +116,7 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
111116
112117 endpoint := "https://api.github.com/user/teams?" + params.Encode()
113118 req, _ := http.NewRequest("GET", endpoint, nil)
114− req.Header.Set("Accept", "application/vnd.github.moondragon+json")
119+ req.Header.Set("Accept", "application/vnd.github.v3+json")
115120 resp, err := http.DefaultClient.Do(req)
116121 if err != nil {
117122 return false, err
@@ -130,12 +135,28 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
130135 return false, fmt.Errorf("%s unmarshaling %s", err, body)
131136 }
132137
138+ var hasOrg bool
139+ presentOrgs := make(map[string]bool)
140+ var presentTeams []string
133141 for _, team := range teams {
142+ presentOrgs[team.Org.Login] = true
134143 if p.Org == team.Org.Login {
135− if p.Team == "" || p.Team == team.Slug {
144+ hasOrg = true
145+ if p.Team == team.Slug {
146+ log.Printf("Found Github Organization:%q Team:%q (Name:%q)", team.Org.Login, team.Slug, team.Name)
136147 return true, nil
137148 }
149+ presentTeams = append(presentTeams, team.Slug)
150+ }
151+ }
152+ if hasOrg {
153+ log.Printf("Missing Team:%q from Org:%q in teams: %v", p.Team, p.Org, presentTeams)
154+ } else {
155+ var allOrgs []string
156+ for org, _ := range presentOrgs {
157+ allOrgs = append(allOrgs, org)
138158 }
159+ log.Printf("Missing Organization:%q in %#v", p.Org, allOrgs)
139160 }
140161 return false, nil
141162}