connectors: refactor filter code into a helper package
I hope I didn't miss any :D Signed-off-by: Stephan Renatus <srenatus@chef.io>
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"golang.org/x/oauth2/github"
|
||||
|
||||
"github.com/dexidp/dex/connector"
|
||||
groups_pkg "github.com/dexidp/dex/pkg/groups"
|
||||
"github.com/dexidp/dex/pkg/log"
|
||||
)
|
||||
|
||||
@@ -375,7 +376,7 @@ func (c *githubConnector) groupsForOrgs(ctx context.Context, client *http.Client
|
||||
// 'teams' list in config.
|
||||
if len(org.Teams) == 0 {
|
||||
inOrgNoTeams = true
|
||||
} else if teams = filterTeams(teams, org.Teams); len(teams) == 0 {
|
||||
} else if teams = groups_pkg.Filter(teams, org.Teams); len(teams) == 0 {
|
||||
c.logger.Infof("github: user %q in org %q but no teams", userName, org.Name)
|
||||
}
|
||||
|
||||
@@ -466,22 +467,6 @@ func (c *githubConnector) userOrgTeams(ctx context.Context, client *http.Client)
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
// Filter the users' team memberships by 'teams' from config.
|
||||
func filterTeams(userTeams, configTeams []string) (teams []string) {
|
||||
teamFilter := make(map[string]struct{})
|
||||
for _, team := range configTeams {
|
||||
if _, ok := teamFilter[team]; !ok {
|
||||
teamFilter[team] = struct{}{}
|
||||
}
|
||||
}
|
||||
for _, team := range userTeams {
|
||||
if _, ok := teamFilter[team]; ok {
|
||||
teams = append(teams, team)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// get creates a "GET `apiURL`" request with context, sends the request using
|
||||
// the client, and decodes the resulting response body into v. A pagination URL
|
||||
// is returned if one exists. Any errors encountered when building requests,
|
||||
|
Reference in New Issue
Block a user