Skip to content

Commit

Permalink
Reorganize SetProject logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfried OLLIVIER committed Sep 23, 2020
1 parent 8400d84 commit 542056e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
5 changes: 2 additions & 3 deletions pkg/validation/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@ func parseProviderInfo(o *options.Options, msgs []string) []string {
case *providers.GitLabProvider:
p.AllowUnverifiedEmail = o.InsecureOIDCAllowUnverifiedEmail
p.Groups = o.GitLabGroup
if len(o.GitlabProjects) > 0 {
p.SetProjects(o.GitlabProjects)
}
p.Projects = o.GitlabProjects
p.SetProjectScope()
p.EmailDomains = o.EmailDomains

if o.GetOIDCVerifier() != nil {
Expand Down
6 changes: 2 additions & 4 deletions providers/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ func (p *GitLabProvider) Redeem(ctx context.Context, redirectURL, code string) (
return
}

// SetProjects adds Projects to a GitLabProvider struct and extends OAuth2 needed scope
func (p *GitLabProvider) SetProjects(projects []string) {
p.Projects = projects
// lazy add read_api to scope if needed
// SetProjectScope ensure read_api is added to scope when filtering on projects
func (p *GitLabProvider) SetProjectScope() {
if !strings.Contains(p.Scope, "read_api") {
p.Scope += " read_api"
}
Expand Down
5 changes: 2 additions & 3 deletions providers/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ var _ = Describe("Gitlab Provider Tests", func() {
p.AllowUnverifiedEmail = true
session := &sessions.SessionState{AccessToken: "gitlab_access_token"}

if len(in.projects) > 0 {
p.SetProjects(in.projects)
}
p.Projects = in.projects
p.SetProjectScope()

if len(in.groups) > 0 {
p.Groups = in.groups
Expand Down

0 comments on commit 542056e

Please sign in to comment.