From b6a4db3f8aa8e991f5d20ae37c7a06480439335a Mon Sep 17 00:00:00 2001 From: Anthony Woods Date: Fri, 24 Apr 2015 00:19:16 +0800 Subject: [PATCH 01/20] always refresh varible options if refresh=true --- public/app/features/templating/templateValuesSrv.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index e933c16796f..3df2c831b6f 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -28,6 +28,9 @@ function (angular, _, kbn) { for (var i = 0; i < this.variables.length; i++) { var variable = this.variables[i]; var urlValue = queryParams['var-' + variable.name]; + if (variable.refresh) { + promises.push(this.updateOptions(variable)); + } if (urlValue !== void 0) { var option = _.findWhere(variable.options, { text: urlValue }); option = option || { text: urlValue, value: urlValue }; @@ -37,9 +40,6 @@ function (angular, _, kbn) { promises.push(promise); } - else if (variable.refresh) { - promises.push(this.updateOptions(variable)); - } else if (variable.type === 'interval') { this.updateAutoInterval(variable); } From c4ac3d61b167a2286d133267023e0890d38a66d4 Mon Sep 17 00:00:00 2001 From: davidak Date: Tue, 28 Apr 2015 20:53:29 +0200 Subject: [PATCH 02/20] add gigabytes as unit --- public/app/components/kbn.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/public/app/components/kbn.js b/public/app/components/kbn.js index fa2b8214873..652b7d6c923 100644 --- a/public/app/components/kbn.js +++ b/public/app/components/kbn.js @@ -376,6 +376,7 @@ function($, _, moment) { kbn.valueFormats.bytes = kbn.formatFuncCreator(1024, [' B', ' KiB', ' MiB', ' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']); kbn.valueFormats.kbytes = kbn.formatFuncCreator(1024, [' KiB', ' MiB', ' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']); kbn.valueFormats.mbytes = kbn.formatFuncCreator(1024, [' MiB', ' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']); + kbn.valueFormats.gbytes = kbn.formatFuncCreator(1024, [' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']); kbn.valueFormats.bps = kbn.formatFuncCreator(1000, [' bps', ' Kbps', ' Mbps', ' Gbps', ' Tbps', ' Pbps', ' Ebps', ' Zbps', ' Ybps']); kbn.valueFormats.Bps = kbn.formatFuncCreator(1000, [' Bps', ' KBps', ' MBps', ' GBps', ' TBps', ' PBps', ' EBps', ' ZBps', ' YBps']); kbn.valueFormats.short = kbn.formatFuncCreator(1000, ['', ' K', ' Mil', ' Bil', ' Tri', ' Qaudr', ' Quint', ' Sext', ' Sept']); @@ -547,6 +548,7 @@ function($, _, moment) { {text: 'bytes', value: 'bytes'}, {text: 'kilobytes', value: 'kbytes'}, {text: 'megabytes', value: 'mbytes'}, + {text: 'gigabytes', value: 'gbytes'}, ] }, { From e5844afb0f394876b5396923a59d56fd96695e65 Mon Sep 17 00:00:00 2001 From: David Raifaizen Date: Tue, 28 Apr 2015 16:29:32 -0400 Subject: [PATCH 03/20] Corrected missing annotations: true tag from the influxdb9 plugin json and fixed influxseries data handling --- .../datasource/influxdb/influxSeries.js | 21 +++++++------------ .../plugins/datasource/influxdb/plugin.json | 3 ++- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/influxSeries.js b/public/app/plugins/datasource/influxdb/influxSeries.js index 9e28884547b..cca01459fc4 100644 --- a/public/app/plugins/datasource/influxdb/influxSeries.js +++ b/public/app/plugins/datasource/influxdb/influxSeries.js @@ -5,7 +5,8 @@ function (_) { 'use strict'; function InfluxSeries(options) { - this.seriesList = options.seriesList; + this.seriesList = options.seriesList && options.seriesList.results && options.seriesList.results.length > 0 + ? options.seriesList.results[0].series || [] : []; this.alias = options.alias; this.annotation = options.annotation; } @@ -17,12 +18,10 @@ function (_) { var self = this; console.log(self.seriesList); - if (!self.seriesList || !self.seriesList.results || !self.seriesList.results[0]) { + if (self.seriesList.length === 0) { return output; } - this.seriesList = self.seriesList.results[0].series; - _.each(self.seriesList, function(series) { var datapoints = []; for (var i = 0; i < series.values.length; i++) { @@ -63,19 +62,15 @@ function (_) { if (column === self.annotation.textColumn) { textCol = index; return; } }); - _.each(series.points, function (point) { + _.each(series.values, function (value) { var data = { annotation: self.annotation, - time: point[timeCol], - title: point[titleCol], - tags: point[tagsCol], - text: point[textCol] + time: + new Date(value[timeCol]), + title: value[titleCol], + tags: value[tagsCol], + text: value[textCol] }; - if (tagsCol) { - data.tags = point[tagsCol]; - } - list.push(data); }); }); diff --git a/public/app/plugins/datasource/influxdb/plugin.json b/public/app/plugins/datasource/influxdb/plugin.json index 40c5fc9cea9..c93b41747a7 100644 --- a/public/app/plugins/datasource/influxdb/plugin.json +++ b/public/app/plugins/datasource/influxdb/plugin.json @@ -13,5 +13,6 @@ "annotations": "app/plugins/datasource/influxdb/partials/annotations.editor.html" }, - "metrics": true + "metrics": true, + "annotations": true } From a0dad3897479533eb8b8b181404876306f4e278a Mon Sep 17 00:00:00 2001 From: Ian Danforth Date: Tue, 28 Apr 2015 15:09:22 -0700 Subject: [PATCH 04/20] Correct deb version number in install guide. --- docs/sources/installation/debian.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/installation/debian.md b/docs/sources/installation/debian.md index 4bba51ec530..c2594e38445 100644 --- a/docs/sources/installation/debian.md +++ b/docs/sources/installation/debian.md @@ -16,7 +16,7 @@ Description | Download $ wget https://grafanarel.s3.amazonaws.com/builds/grafana_2.0.2_amd64.deb $ sudo apt-get install -y adduser libfontconfig - $ sudo dpkg -i grafana_2.0.1_amd64.deb + $ sudo dpkg -i grafana_2.0.2_amd64.deb ## APT Repository Add the following line to your `/etc/apt/sources.list` From 7ea579bb71cf1d505c815d5907b4d8910772a488 Mon Sep 17 00:00:00 2001 From: Garrett Bjerkhoel Date: Tue, 28 Apr 2015 20:19:48 -0700 Subject: [PATCH 05/20] Add team_ids configuration option --- conf/defaults.ini | 1 + pkg/social/social.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 6bb3fb80857..7345f18520e 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -140,6 +140,7 @@ enabled = false client_id = some_id client_secret = some_secret scopes = user:email +team_ids = auth_url = https://github.com/login/oauth/authorize token_url = https://github.com/login/oauth/access_token api_url = https://api.github.com/user diff --git a/pkg/social/social.go b/pkg/social/social.go index 47c7ea5dc38..c19784e34e1 100644 --- a/pkg/social/social.go +++ b/pkg/social/social.go @@ -75,7 +75,8 @@ func NewOAuthService() { // GitHub. if name == "github" { setting.OAuthService.GitHub = true - SocialMap["github"] = &SocialGithub{Config: &config, allowedDomains: info.AllowedDomains, ApiUrl: info.ApiUrl, allowSignup: info.AllowSignup} + teamIds := sec.Key("team_ids").Ints(",") + SocialMap["github"] = &SocialGithub{Config: &config, allowedDomains: info.AllowedDomains, ApiUrl: info.ApiUrl, allowSignup: info.AllowSignup, teamIds: teamIds} } // Google. @@ -105,6 +106,7 @@ type SocialGithub struct { allowedDomains []string ApiUrl string allowSignup bool + teamIds []int } func (s *SocialGithub) Type() int { From 979d0ca70f5aec638ce6e6bb8c8f69f47973f221 Mon Sep 17 00:00:00 2001 From: Garrett Bjerkhoel Date: Tue, 28 Apr 2015 20:21:44 -0700 Subject: [PATCH 06/20] Add new error type for team membership permissions --- pkg/social/social.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/social/social.go b/pkg/social/social.go index c19784e34e1..752ed7114c2 100644 --- a/pkg/social/social.go +++ b/pkg/social/social.go @@ -5,6 +5,7 @@ import ( "fmt" "strconv" "strings" + "errors" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/setting" @@ -109,6 +110,10 @@ type SocialGithub struct { teamIds []int } +var ( + ErrMissingTeamMembership = errors.New("User not a member of one of the required teams") +) + func (s *SocialGithub) Type() int { return int(models.GITHUB) } From eb37fc089b01aba3d046635e60596e8d82dc1601 Mon Sep 17 00:00:00 2001 From: Garrett Bjerkhoel Date: Tue, 28 Apr 2015 20:22:21 -0700 Subject: [PATCH 07/20] Check for active team membership when fetching s.UserInfo --- pkg/social/social.go | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/pkg/social/social.go b/pkg/social/social.go index 752ed7114c2..2b716495d53 100644 --- a/pkg/social/social.go +++ b/pkg/social/social.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" "errors" + "net/http" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/setting" @@ -126,6 +127,28 @@ func (s *SocialGithub) IsSignupAllowed() bool { return s.allowSignup } +func (s *SocialGithub) IsTeamMember(client *http.Client, username string, teamId int) bool { + var data struct { + Url string `json:"url"` + State string `json:"state"` + } + + membershipUrl := fmt.Sprintf("https://api.github.com/teams/%d/memberships/%s", teamId, username) + r, err := client.Get(membershipUrl) + if err != nil { + return false + } + + defer r.Body.Close() + + if err = json.NewDecoder(r.Body).Decode(&data); err != nil { + return false + } + + active := data.State == "active" + return active +} + func (s *SocialGithub) UserInfo(token *oauth2.Token) (*BasicUserInfo, error) { var data struct { Id int `json:"id"` @@ -146,11 +169,23 @@ func (s *SocialGithub) UserInfo(token *oauth2.Token) (*BasicUserInfo, error) { return nil, err } - return &BasicUserInfo{ + userInfo := &BasicUserInfo{ Identity: strconv.Itoa(data.Id), Name: data.Name, Email: data.Email, - }, nil + } + + if len(s.teamIds) > 0 { + for _, teamId := range s.teamIds { + if s.IsTeamMember(client, data.Name, teamId) { + return userInfo, nil + } + } + + return nil, ErrMissingTeamMembership + } else { + return userInfo, nil + } } // ________ .__ From 1d7f9452685f5f2d41224afbf659bb922636a8bc Mon Sep 17 00:00:00 2001 From: Garrett Bjerkhoel Date: Tue, 28 Apr 2015 20:22:45 -0700 Subject: [PATCH 08/20] Handle special error case if connect.UserInfo returns an error --- pkg/api/login_oauth.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/api/login_oauth.go b/pkg/api/login_oauth.go index 11d62754a18..d89a7237d35 100644 --- a/pkg/api/login_oauth.go +++ b/pkg/api/login_oauth.go @@ -45,7 +45,11 @@ func OAuthLogin(ctx *middleware.Context) { userInfo, err := connect.UserInfo(token) if err != nil { - ctx.Handle(500, fmt.Sprintf("login.OAuthLogin(get info from %s)", name), err) + if err == social.ErrMissingTeamMembership { + ctx.Redirect(setting.AppSubUrl + "/login?missing_team_membership=1") + } else { + ctx.Handle(500, fmt.Sprintf("login.OAuthLogin(get info from %s)", name), err) + } return } From 1fdc5277ae875b50ee680dcc7f162ef716cdc9c4 Mon Sep 17 00:00:00 2001 From: Garrett Bjerkhoel Date: Tue, 28 Apr 2015 20:38:05 -0700 Subject: [PATCH 09/20] Update documentation for team_ids option --- docs/sources/installation/configuration.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index a79a8494d73..a1dfb6ac035 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -179,6 +179,7 @@ Client ID and a Client Secret. Specify these in the grafana config file. Example client_id = YOUR_GITHUB_APP_CLIENT_ID client_secret = YOUR_GITHUB_APP_CLIENT_SECRET scopes = user:email + team_ids = auth_url = https://github.com/login/oauth/authorize token_url = https://github.com/login/oauth/access_token allow_sign_up = false @@ -189,6 +190,21 @@ now login or signup with your github accounts. You may allow users to sign-up via github auth by setting allow_sign_up to true. When this option is set to true, any user successfully authenticating via github auth will be automatically signed up. +### team_ids +Require an active team membership for at least one of the given teams on GitHub. +If the authenticated user isn't a member of at least one the teams they will not +be able to register or authenticate with your Grafana instance. Example: + + [auth.github] + enabled = true + client_id = YOUR_GITHUB_APP_CLIENT_ID + client_secret = YOUR_GITHUB_APP_CLIENT_SECRET + scopes = user:email + team_ids = 150,300 + auth_url = https://github.com/login/oauth/authorize + token_url = https://github.com/login/oauth/access_token + allow_sign_up = false + ## [auth.google] You need to create a google project. You can do this in the [Google Developer Console](https://console.developers.google.com/project). When you create the project you will need to specify a callback URL. Specify this as callback: @@ -257,5 +273,3 @@ enabled. Counters are sent every 24 hours. Default value is `true`. ### google_analytics_ua_id If you want to track Grafana usage via Google analytics specify *your* Univeral Analytics ID here. By defualt this feature is disabled. - - From b72eba1ef223e2476ab4a04663ad74da1b58d1a6 Mon Sep 17 00:00:00 2001 From: Anthony Woods Date: Wed, 29 Apr 2015 14:55:39 +0800 Subject: [PATCH 10/20] refactor handling of refresh when urlValues being used for templates. fixes #1862 --- .../features/templating/templateValuesSrv.js | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index 3df2c831b6f..10ff556bf84 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -28,17 +28,11 @@ function (angular, _, kbn) { for (var i = 0; i < this.variables.length; i++) { var variable = this.variables[i]; var urlValue = queryParams['var-' + variable.name]; - if (variable.refresh) { - promises.push(this.updateOptions(variable)); - } if (urlValue !== void 0) { - var option = _.findWhere(variable.options, { text: urlValue }); - option = option || { text: urlValue, value: urlValue }; - - var promise = this.setVariableValue(variable, option, true); - this.updateAutoInterval(variable); - - promises.push(promise); + promises.push(this.setVariableFromUrl(variable, urlValue)); + } + else if (variable.refresh) { + promises.push(this.updateOptions(variable)); } else if (variable.type === 'interval') { this.updateAutoInterval(variable); @@ -48,6 +42,25 @@ function (angular, _, kbn) { return $q.all(promises); }; + this.setVariableFromUrl = function(variable, urlValue) { + if (variable.refresh) { + var self = this; + //refresh the list of options before setting the value + return this.updateOptions(variable).then(function() { + var option = _.findWhere(variable.options, { text: urlValue }); + option = option || { text: urlValue, value: urlValue }; + + self.updateAutoInterval(variable); + return self.setVariableValue(variable, option); + }); + } + var option = _.findWhere(variable.options, { text: urlValue }); + option = option || { text: urlValue, value: urlValue }; + + this.updateAutoInterval(variable); + return this.setVariableValue(variable, option); + }; + this.updateAutoInterval = function(variable) { if (!variable.auto) { return; } From 81636d8634fa21f60a867ca4a11a270df883d473 Mon Sep 17 00:00:00 2001 From: Anthony Woods Date: Wed, 29 Apr 2015 15:14:49 +0800 Subject: [PATCH 11/20] expose orgId via currentUser object. fixes #1907 --- pkg/api/dtos/models.go | 1 + pkg/api/index.go | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index 0057f78ff0d..a14ff55c079 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -23,6 +23,7 @@ type CurrentUser struct { LightTheme bool `json:"lightTheme"` OrgRole m.RoleType `json:"orgRole"` OrgName string `json:"orgName"` + OrgId int64 `json:"orgId"` IsGrafanaAdmin bool `json:"isGrafanaAdmin"` GravatarUrl string `json:"gravatarUrl"` } diff --git a/pkg/api/index.go b/pkg/api/index.go index d9ecf65b699..6e880b1d066 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -20,6 +20,7 @@ func setIndexViewData(c *middleware.Context) error { LightTheme: c.Theme == "light", OrgName: c.OrgName, OrgRole: c.OrgRole, + OrgId: c.OrgId, GravatarUrl: dtos.GetGravatarUrl(c.Email), IsGrafanaAdmin: c.IsGrafanaAdmin, } From e7c43bf614ae380c99f9cf09b4bdbb100088efad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 29 Apr 2015 09:26:12 +0200 Subject: [PATCH 12/20] expose org id to frontend, Closes #1907 --- pkg/api/dtos/models.go | 3 ++- pkg/api/index.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index 0057f78ff0d..fea88f07550 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -21,8 +21,9 @@ type CurrentUser struct { Email string `json:"email"` Name string `json:"name"` LightTheme bool `json:"lightTheme"` - OrgRole m.RoleType `json:"orgRole"` + OrgId int64 `json:"orgId"` OrgName string `json:"orgName"` + OrgRole m.RoleType `json:"orgRole"` IsGrafanaAdmin bool `json:"isGrafanaAdmin"` GravatarUrl string `json:"gravatarUrl"` } diff --git a/pkg/api/index.go b/pkg/api/index.go index d9ecf65b699..86a5e3f1882 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -18,6 +18,7 @@ func setIndexViewData(c *middleware.Context) error { Email: c.Email, Name: c.Name, LightTheme: c.Theme == "light", + OrgId: c.OrgId, OrgName: c.OrgName, OrgRole: c.OrgRole, GravatarUrl: dtos.GetGravatarUrl(c.Email), From 884dc53f8a7bf963e802eb551fc845749516d6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 29 Apr 2015 09:49:22 +0200 Subject: [PATCH 13/20] =?UTF-8?q?smal=C4=BA=20refactorings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/social/social.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/pkg/social/social.go b/pkg/social/social.go index 2b716495d53..355f85b54b6 100644 --- a/pkg/social/social.go +++ b/pkg/social/social.go @@ -2,11 +2,11 @@ package social import ( "encoding/json" + "errors" "fmt" + "net/http" "strconv" "strings" - "errors" - "net/http" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/setting" @@ -78,13 +78,23 @@ func NewOAuthService() { if name == "github" { setting.OAuthService.GitHub = true teamIds := sec.Key("team_ids").Ints(",") - SocialMap["github"] = &SocialGithub{Config: &config, allowedDomains: info.AllowedDomains, ApiUrl: info.ApiUrl, allowSignup: info.AllowSignup, teamIds: teamIds} + SocialMap["github"] = &SocialGithub{ + Config: &config, + allowedDomains: info.AllowedDomains, + apiUrl: info.ApiUrl, + allowSignup: info.AllowSignup, + teamIds: teamIds, + } } // Google. if name == "google" { setting.OAuthService.Google = true - SocialMap["google"] = &SocialGoogle{Config: &config, allowedDomains: info.AllowedDomains, ApiUrl: info.ApiUrl, allowSignup: info.AllowSignup} + SocialMap["google"] = &SocialGoogle{ + Config: &config, allowedDomains: info.AllowedDomains, + apiUrl: info.ApiUrl, + allowSignup: info.AllowSignup, + } } } } @@ -106,7 +116,7 @@ func isEmailAllowed(email string, allowedDomains []string) bool { type SocialGithub struct { *oauth2.Config allowedDomains []string - ApiUrl string + apiUrl string allowSignup bool teamIds []int } @@ -129,8 +139,8 @@ func (s *SocialGithub) IsSignupAllowed() bool { func (s *SocialGithub) IsTeamMember(client *http.Client, username string, teamId int) bool { var data struct { - Url string `json:"url"` - State string `json:"state"` + Url string `json:"url"` + State string `json:"state"` } membershipUrl := fmt.Sprintf("https://api.github.com/teams/%d/memberships/%s", teamId, username) @@ -158,7 +168,7 @@ func (s *SocialGithub) UserInfo(token *oauth2.Token) (*BasicUserInfo, error) { var err error client := s.Client(oauth2.NoContext, token) - r, err := client.Get(s.ApiUrl) + r, err := client.Get(s.apiUrl) if err != nil { return nil, err } @@ -198,7 +208,7 @@ func (s *SocialGithub) UserInfo(token *oauth2.Token) (*BasicUserInfo, error) { type SocialGoogle struct { *oauth2.Config allowedDomains []string - ApiUrl string + apiUrl string allowSignup bool } @@ -223,7 +233,7 @@ func (s *SocialGoogle) UserInfo(token *oauth2.Token) (*BasicUserInfo, error) { var err error client := s.Client(oauth2.NoContext, token) - r, err := client.Get(s.ApiUrl) + r, err := client.Get(s.apiUrl) if err != nil { return nil, err } From 32fa8180fa2bc3c57192a6dce93e34cc4761ad35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 29 Apr 2015 09:52:52 +0200 Subject: [PATCH 14/20] Github OAuth: You can now configure a Github team membership requirement, Closes #1731 --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9133bf8601..70aaa67ab22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ -# 2.0.3 (unreleased) +# 2.1.0 (unreleased - master branch) + +**Backend** +- [Issue #1905](https://github.com/grafana/grafana/issues/1905). Github OAuth: You can now configure a Github team membership requirement, thx @dewski + + +# 2.0.3 (unreleased - 2.0.x branch) **Fixes** - [Issue #1872](https://github.com/grafana/grafana/issues/1872). Firefox/IE issue, invisible text in dashboard search fixed From 0d3fbb865929becce7ff5cc72ab0a15d4f1b7da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 29 Apr 2015 10:08:01 +0200 Subject: [PATCH 15/20] Added message alerts when login failed due to github team membership or email domain requirement, #1731, #1660 --- conf/sample.ini | 7 +++---- pkg/api/login_oauth.go | 5 +++-- public/app/controllers/loginCtrl.js | 9 ++++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/conf/sample.ini b/conf/sample.ini index 68bd3eb3a1d..4ebab72d1af 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -142,8 +142,8 @@ ;auth_url = https://github.com/login/oauth/authorize ;token_url = https://github.com/login/oauth/access_token ;api_url = https://api.github.com/user -# Uncomment bellow to only allow specific email domains -; allowed_domains = mycompany.com othercompany.com +;team_ids = +;allowed_domains = #################################### Google Auth ########################## [auth.google] @@ -154,8 +154,7 @@ ;auth_url = https://accounts.google.com/o/oauth2/auth ;token_url = https://accounts.google.com/o/oauth2/token ;api_url = https://www.googleapis.com/oauth2/v1/userinfo -# Uncomment bellow to only allow specific email domains -; allowed_domains = mycompany.com othercompany.com +;allowed_domains = #################################### Logging ########################## [log] diff --git a/pkg/api/login_oauth.go b/pkg/api/login_oauth.go index d89a7237d35..505c17ddde8 100644 --- a/pkg/api/login_oauth.go +++ b/pkg/api/login_oauth.go @@ -3,6 +3,7 @@ package api import ( "errors" "fmt" + "net/url" "golang.org/x/oauth2" @@ -46,7 +47,7 @@ func OAuthLogin(ctx *middleware.Context) { userInfo, err := connect.UserInfo(token) if err != nil { if err == social.ErrMissingTeamMembership { - ctx.Redirect(setting.AppSubUrl + "/login?missing_team_membership=1") + ctx.Redirect(setting.AppSubUrl + "/login?failedMsg=" + url.QueryEscape("Required Github team membership not fulfilled")) } else { ctx.Handle(500, fmt.Sprintf("login.OAuthLogin(get info from %s)", name), err) } @@ -58,7 +59,7 @@ func OAuthLogin(ctx *middleware.Context) { // validate that the email is allowed to login to grafana if !connect.IsEmailAllowed(userInfo.Email) { log.Info("OAuth login attempt with unallowed email, %s", userInfo.Email) - ctx.Redirect(setting.AppSubUrl + "/login?email_not_allowed=1") + ctx.Redirect(setting.AppSubUrl + "/login?failedMsg=" + url.QueryEscape("Required email domain not fulfilled")) return } diff --git a/public/app/controllers/loginCtrl.js b/public/app/controllers/loginCtrl.js index 5de773842f8..c8856df0690 100644 --- a/public/app/controllers/loginCtrl.js +++ b/public/app/controllers/loginCtrl.js @@ -7,7 +7,7 @@ function (angular, config) { var module = angular.module('grafana.controllers'); - module.controller('LoginCtrl', function($scope, backendSrv, contextSrv) { + module.controller('LoginCtrl', function($scope, backendSrv, contextSrv, $location) { $scope.formModel = { user: '', email: '', @@ -28,6 +28,13 @@ function (angular, config) { $scope.init = function() { $scope.$watch("loginMode", $scope.loginModeChanged); $scope.passwordChanged(); + + var params = $location.search(); + if (params.failedMsg) { + $scope.appEvent('alert-warning', ['Login Failed', params.failedMsg]); + delete params.failedMsg; + $location.search(params); + } }; // build info view model From 3007add4ca4ddb865fb20216c49aa14c00066ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 29 Apr 2015 10:10:44 +0200 Subject: [PATCH 16/20] small docs fix --- docs/sources/installation/debian.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/installation/debian.md b/docs/sources/installation/debian.md index cf5e4f4f072..aed4eb420b5 100644 --- a/docs/sources/installation/debian.md +++ b/docs/sources/installation/debian.md @@ -16,7 +16,7 @@ Description | Download $ wget https://grafanarel.s3.amazonaws.com/builds/grafana_2.0.1_amd64.deb $ sudo apt-get install -y adduser libfontconfig - $ sudo dpkg -i grafana_2.0.1_amd64.deb + $ sudo dpkg -i grafana_2.0.2_amd64.deb ## APT Repository Add the following line to your `/etc/apt/sources.list` From a0e80e5869aee5835151b3156a36e0a1a6498cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 29 Apr 2015 10:13:00 +0200 Subject: [PATCH 17/20] Updated 2.0 docs, merged with master and removed docs for features in 2.1, doc updates related to 2.0 needs to be done to this branch --- docs/sources/installation/configuration.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index a1dfb6ac035..f55561e6668 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -179,7 +179,6 @@ Client ID and a Client Secret. Specify these in the grafana config file. Example client_id = YOUR_GITHUB_APP_CLIENT_ID client_secret = YOUR_GITHUB_APP_CLIENT_SECRET scopes = user:email - team_ids = auth_url = https://github.com/login/oauth/authorize token_url = https://github.com/login/oauth/access_token allow_sign_up = false @@ -190,21 +189,6 @@ now login or signup with your github accounts. You may allow users to sign-up via github auth by setting allow_sign_up to true. When this option is set to true, any user successfully authenticating via github auth will be automatically signed up. -### team_ids -Require an active team membership for at least one of the given teams on GitHub. -If the authenticated user isn't a member of at least one the teams they will not -be able to register or authenticate with your Grafana instance. Example: - - [auth.github] - enabled = true - client_id = YOUR_GITHUB_APP_CLIENT_ID - client_secret = YOUR_GITHUB_APP_CLIENT_SECRET - scopes = user:email - team_ids = 150,300 - auth_url = https://github.com/login/oauth/authorize - token_url = https://github.com/login/oauth/access_token - allow_sign_up = false - ## [auth.google] You need to create a google project. You can do this in the [Google Developer Console](https://console.developers.google.com/project). When you create the project you will need to specify a callback URL. Specify this as callback: From 4c7545e909df74299b91b29be556e4acd888398a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 29 Apr 2015 10:13:52 +0200 Subject: [PATCH 18/20] Updated docs Makefile --- docs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Makefile b/docs/Makefile index d44bc545e2c..fcb1708f916 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -44,7 +44,7 @@ docs-test: docs-build $(DOCKER_RUN_DOCS) "$(DOCKER_DOCS_IMAGE)" ./test.sh docs-build: - git fetch https://github.com/grafana/grafana.git docs-2.0 && git diff --name-status FETCH_HEAD...HEAD -- . > changed-files + git fetch https://github.com/grafana/grafana.git docs-1.x && git diff --name-status FETCH_HEAD...HEAD -- . > changed-files echo "$(GIT_BRANCH)" > GIT_BRANCH echo "$(GITCOMMIT)" > GITCOMMIT docker build -t "$(DOCKER_DOCS_IMAGE)" . From 9ae3d66da72dc53a7eae2430524292bace801b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 29 Apr 2015 10:18:11 +0200 Subject: [PATCH 19/20] Fixed docs, screencasts page --- docs/sources/guides/screencasts.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/sources/guides/screencasts.md b/docs/sources/guides/screencasts.md index 6c09e5b26af..d8c605a4245 100644 --- a/docs/sources/guides/screencasts.md +++ b/docs/sources/guides/screencasts.md @@ -15,10 +15,9 @@ no_toc: true

Episode 2 - Templated Graphite Queries

- +
-
@@ -34,7 +33,6 @@ no_toc: true
-
@@ -50,7 +48,6 @@ no_toc: true
-
From 74a8fa61f2217c6a63d9d08394c8086173632c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 29 Apr 2015 10:33:37 +0200 Subject: [PATCH 20/20] Merged with 2.0 docs and restored some stuff --- conf/defaults.ini | 6 +++--- conf/sample.ini | 2 ++ docs/sources/installation/configuration.md | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 7345f18520e..4fef290b908 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -137,19 +137,20 @@ org_role = Viewer #################################### Github Auth ########################## [auth.github] enabled = false +allow_sign_up = false client_id = some_id client_secret = some_secret scopes = user:email -team_ids = auth_url = https://github.com/login/oauth/authorize token_url = https://github.com/login/oauth/access_token api_url = https://api.github.com/user +team_ids = allowed_domains = -allow_sign_up = false #################################### Google Auth ########################## [auth.google] enabled = false +allow_sign_up = false client_id = some_client_id client_secret = some_client_secret scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email @@ -157,7 +158,6 @@ auth_url = https://accounts.google.com/o/oauth2/auth token_url = https://accounts.google.com/o/oauth2/token api_url = https://www.googleapis.com/oauth2/v1/userinfo allowed_domains = -allow_sign_up = false #################################### Logging ########################## [log] diff --git a/conf/sample.ini b/conf/sample.ini index 4ebab72d1af..62d5c2a09ce 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -136,6 +136,7 @@ #################################### Github Auth ########################## [auth.github] ;enabled = false +;allow_sign_up = false ;client_id = some_id ;client_secret = some_secret ;scopes = user:email @@ -148,6 +149,7 @@ #################################### Google Auth ########################## [auth.google] ;enabled = false +;allow_sign_up = false ;client_id = some_client_id ;client_secret = some_client_secret ;scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index f55561e6668..ace8c57184f 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -182,6 +182,7 @@ Client ID and a Client Secret. Specify these in the grafana config file. Example auth_url = https://github.com/login/oauth/authorize token_url = https://github.com/login/oauth/access_token allow_sign_up = false + team_ids = Restart the grafana backend. You should now see a github login button on the login page. You can now login or signup with your github accounts. @@ -189,6 +190,21 @@ now login or signup with your github accounts. You may allow users to sign-up via github auth by setting allow_sign_up to true. When this option is set to true, any user successfully authenticating via github auth will be automatically signed up. +### team_ids +Require an active team membership for at least one of the given teams on GitHub. +If the authenticated user isn't a member of at least one the teams they will not +be able to register or authenticate with your Grafana instance. Example: + + [auth.github] + enabled = true + client_id = YOUR_GITHUB_APP_CLIENT_ID + client_secret = YOUR_GITHUB_APP_CLIENT_SECRET + scopes = user:email + team_ids = 150,300 + auth_url = https://github.com/login/oauth/authorize + token_url = https://github.com/login/oauth/access_token + allow_sign_up = false + ## [auth.google] You need to create a google project. You can do this in the [Google Developer Console](https://console.developers.google.com/project). When you create the project you will need to specify a callback URL. Specify this as callback: