aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Lyda <kevin@ie.suberic.net>2017-01-23 22:55:53 +0000
committerNiall Sheridan <nsheridan@gmail.com>2017-01-25 00:52:02 +0000
commit71b508cc61f69c5905ac02e4924cd80a04299187 (patch)
tree306fa762743a36e73b255aee27d91a14f6804206
parent17d06d3003a796c76c7c5d8bfb0cab0aeb1bbf8f (diff)
Code cleanup.
Use ParseBool instead of writing it on own. Use c.newClient(token) to get an http client.
-rw-r--r--server/auth/gitlab/gitlab.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/server/auth/gitlab/gitlab.go b/server/auth/gitlab/gitlab.go
index 4aeb616..bd7eb8e 100644
--- a/server/auth/gitlab/gitlab.go
+++ b/server/auth/gitlab/gitlab.go
@@ -3,6 +3,7 @@ package gitlab
import (
"errors"
"net/http"
+ "strconv"
"github.com/nsheridan/cashier/server/auth"
"github.com/nsheridan/cashier/server/config"
@@ -31,10 +32,7 @@ func New(c *config.Auth) (auth.Provider, error) {
for _, u := range c.UsersWhitelist {
uw[u] = true
}
- allUsers := false
- if c.ProviderOpts["allusers"] == "true" {
- allUsers = true
- }
+ allUsers, _ := strconv.ParseBool(c.ProviderOpts["allusers"])
if !allUsers && c.ProviderOpts["group"] == "" && len(uw) == 0 {
return nil, errors.New("gitlab_opts group and the users whitelist must not be both empty if allusers isn't true")
}
@@ -96,7 +94,7 @@ func (c *Config) Valid(token *oauth2.Token) bool {
// here if user whitelist is set and user is in whitelist.
return true
}
- client := gitlabapi.NewOAuthClient(nil, token.AccessToken)
+ client := gitlabapi.NewOAuthClient(c.newClient(token), token.AccessToken)
client.SetBaseURL(c.baseurl)
groups, _, err := client.Groups.SearchGroup(c.group)
if err != nil {
@@ -131,7 +129,7 @@ func (c *Config) Exchange(code string) (*oauth2.Token, error) {
// Username retrieves the username of the Gitlab user.
func (c *Config) Username(token *oauth2.Token) string {
- client := gitlabapi.NewOAuthClient(nil, token.AccessToken)
+ client := gitlabapi.NewOAuthClient(c.newClient(token), token.AccessToken)
client.SetBaseURL(c.baseurl)
u, _, err := client.Users.CurrentUser()
if err != nil {