diff options
author | Kevin Lyda <kevin@ie.suberic.net> | 2017-02-12 14:38:12 +0000 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2017-02-12 14:38:12 +0000 |
commit | ed8bc523fd0d1a66acf3fa449c453508035efdfc (patch) | |
tree | c05849546e1dd9d771dcc4c4ff52056d249a95fb /server/auth/gitlab | |
parent | 9c344a0a95c44ef9cebade7b8a65ac160d9eb900 (diff) |
Initial pass at prometheus support. (#56)
Diffstat (limited to 'server/auth/gitlab')
-rw-r--r-- | server/auth/gitlab/gitlab.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/server/auth/gitlab/gitlab.go b/server/auth/gitlab/gitlab.go index f76b2e8..2cf2a5c 100644 --- a/server/auth/gitlab/gitlab.go +++ b/server/auth/gitlab/gitlab.go @@ -6,6 +6,7 @@ import ( "github.com/nsheridan/cashier/server/auth" "github.com/nsheridan/cashier/server/config" + "github.com/nsheridan/cashier/server/metrics" gitlabapi "github.com/xanzy/go-gitlab" "golang.org/x/oauth2" @@ -78,6 +79,7 @@ func (c *Config) Valid(token *oauth2.Token) bool { return false } if c.allusers { + metrics.M.AuthValid.WithLabelValues("gitlab").Inc() return true } if len(c.whitelist) > 0 && !c.whitelist[c.Username(token)] { @@ -86,6 +88,7 @@ func (c *Config) Valid(token *oauth2.Token) bool { if c.group == "" { // There's no group and token is valid. Can only reach // here if user whitelist is set and user is in whitelist. + metrics.M.AuthValid.WithLabelValues("gitlab").Inc() return true } client := gitlabapi.NewOAuthClient(nil, token.AccessToken) @@ -96,6 +99,7 @@ func (c *Config) Valid(token *oauth2.Token) bool { } for _, g := range groups { if g.Path == c.group { + metrics.M.AuthValid.WithLabelValues("gitlab").Inc() return true } } @@ -118,7 +122,11 @@ func (c *Config) StartSession(state string) *auth.Session { // Exchange authorizes the session and returns an access token. func (c *Config) Exchange(code string) (*oauth2.Token, error) { - return c.config.Exchange(oauth2.NoContext, code) + t, err := c.config.Exchange(oauth2.NoContext, code) + if err == nil { + metrics.M.AuthExchange.WithLabelValues("gitlab").Inc() + } + return t, err } // Username retrieves the username of the Gitlab user. |