mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #6952 from huydx/format-gofmt
(format) run go fmt in pkg
This commit is contained in:
commit
38d8ba8faa
@ -55,8 +55,8 @@ func OAuthLogin(ctx *middleware.Context) {
|
|||||||
ctx.Session.Set(middleware.SESS_KEY_OAUTH_STATE, state)
|
ctx.Session.Set(middleware.SESS_KEY_OAUTH_STATE, state)
|
||||||
if setting.OAuthService.OAuthInfos[name].HostedDomain == "" {
|
if setting.OAuthService.OAuthInfos[name].HostedDomain == "" {
|
||||||
ctx.Redirect(connect.AuthCodeURL(state, oauth2.AccessTypeOnline))
|
ctx.Redirect(connect.AuthCodeURL(state, oauth2.AccessTypeOnline))
|
||||||
}else{
|
} else {
|
||||||
ctx.Redirect(connect.AuthCodeURL(state, oauth2.SetParam("hd", setting.OAuthService.OAuthInfos[name].HostedDomain), oauth2.AccessTypeOnline));
|
ctx.Redirect(connect.AuthCodeURL(state, oauth2.SetParam("hd", setting.OAuthService.OAuthInfos[name].HostedDomain), oauth2.AccessTypeOnline))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -90,8 +90,8 @@ func OAuthLogin(ctx *middleware.Context) {
|
|||||||
tr := &http.Transport{
|
tr := &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{
|
TLSClientConfig: &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: []tls.Certificate{cert},
|
||||||
RootCAs: caCertPool,
|
RootCAs: caCertPool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
sslcli := &http.Client{Transport: tr}
|
sslcli := &http.Client{Transport: tr}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SESS_KEY_USERID = "uid"
|
SESS_KEY_USERID = "uid"
|
||||||
SESS_KEY_OAUTH_STATE = "state"
|
SESS_KEY_OAUTH_STATE = "state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ func (db *Mysql) AutoIncrStr() string {
|
|||||||
|
|
||||||
func (db *Mysql) BooleanStr(value bool) string {
|
func (db *Mysql) BooleanStr(value bool) string {
|
||||||
if value {
|
if value {
|
||||||
return "1"
|
return "1"
|
||||||
}
|
}
|
||||||
return "0"
|
return "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Mysql) SqlType(c *Column) string {
|
func (db *Mysql) SqlType(c *Column) string {
|
||||||
|
@ -23,13 +23,12 @@ import (
|
|||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type DatabaseConfig struct {
|
type DatabaseConfig struct {
|
||||||
Type, Host, Name, User, Pwd, Path, SslMode string
|
Type, Host, Name, User, Pwd, Path, SslMode string
|
||||||
CaCertPath string
|
CaCertPath string
|
||||||
ClientKeyPath string
|
ClientKeyPath string
|
||||||
ClientCertPath string
|
ClientCertPath string
|
||||||
ServerCertName string
|
ServerCertName string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -38,10 +37,10 @@ var (
|
|||||||
|
|
||||||
HasEngine bool
|
HasEngine bool
|
||||||
|
|
||||||
DbCfg DatabaseConfig
|
DbCfg DatabaseConfig
|
||||||
|
|
||||||
UseSQLite3 bool
|
UseSQLite3 bool
|
||||||
sqlog log.Logger = log.New("sqlstore")
|
sqlog log.Logger = log.New("sqlstore")
|
||||||
)
|
)
|
||||||
|
|
||||||
func EnsureAdminUser() {
|
func EnsureAdminUser() {
|
||||||
@ -187,9 +186,9 @@ func LoadConfig() {
|
|||||||
UseSQLite3 = true
|
UseSQLite3 = true
|
||||||
}
|
}
|
||||||
DbCfg.SslMode = sec.Key("ssl_mode").String()
|
DbCfg.SslMode = sec.Key("ssl_mode").String()
|
||||||
DbCfg.CaCertPath = sec.Key("ca_cert_path").String()
|
DbCfg.CaCertPath = sec.Key("ca_cert_path").String()
|
||||||
DbCfg.ClientKeyPath = sec.Key("client_key_path").String()
|
DbCfg.ClientKeyPath = sec.Key("client_key_path").String()
|
||||||
DbCfg.ClientCertPath = sec.Key("client_cert_path").String()
|
DbCfg.ClientCertPath = sec.Key("client_cert_path").String()
|
||||||
DbCfg.ServerCertName = sec.Key("server_cert_name").String()
|
DbCfg.ServerCertName = sec.Key("server_cert_name").String()
|
||||||
DbCfg.Path = sec.Key("path").MustString("data/grafana.db")
|
DbCfg.Path = sec.Key("path").MustString("data/grafana.db")
|
||||||
}
|
}
|
||||||
|
@ -181,12 +181,12 @@ func (s *GenericOAuth) UserInfo(client *http.Client) (*BasicUserInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userInfo := &BasicUserInfo{
|
userInfo := &BasicUserInfo{
|
||||||
Name: data.Name,
|
Name: data.Name,
|
||||||
Login: data.Login,
|
Login: data.Login,
|
||||||
Email: data.Email,
|
Email: data.Email,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userInfo.Email == "" && data.Attributes["email:primary"] != nil) {
|
if userInfo.Email == "" && data.Attributes["email:primary"] != nil {
|
||||||
userInfo.Email = data.Attributes["email:primary"][0]
|
userInfo.Email = data.Attributes["email:primary"][0]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,11 +197,11 @@ func (s *GenericOAuth) UserInfo(client *http.Client) (*BasicUserInfo, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userInfo.Login == "" && data.Username != "") {
|
if userInfo.Login == "" && data.Username != "" {
|
||||||
userInfo.Login = data.Username
|
userInfo.Login = data.Username
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userInfo.Login == "") {
|
if userInfo.Login == "" {
|
||||||
userInfo.Login = data.Email
|
userInfo.Login = data.Email
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,9 +187,9 @@ func (s *SocialGithub) UserInfo(client *http.Client) (*BasicUserInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userInfo := &BasicUserInfo{
|
userInfo := &BasicUserInfo{
|
||||||
Name: data.Login,
|
Name: data.Login,
|
||||||
Login: data.Login,
|
Login: data.Login,
|
||||||
Email: data.Email,
|
Email: data.Email,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.IsTeamMember(client) {
|
if !s.IsTeamMember(client) {
|
||||||
|
@ -45,8 +45,8 @@ func (s *SocialGoogle) UserInfo(client *http.Client) (*BasicUserInfo, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &BasicUserInfo{
|
return &BasicUserInfo{
|
||||||
Name: data.Name,
|
Name: data.Name,
|
||||||
Email: data.Email,
|
Email: data.Email,
|
||||||
Login: data.Email,
|
Login: data.Email,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,10 @@ func (s *SocialGrafanaNet) IsOrganizationMember(organizations []OrgRecord) bool
|
|||||||
|
|
||||||
func (s *SocialGrafanaNet) UserInfo(client *http.Client) (*BasicUserInfo, error) {
|
func (s *SocialGrafanaNet) UserInfo(client *http.Client) (*BasicUserInfo, error) {
|
||||||
var data struct {
|
var data struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Login string `json:"username"`
|
Login string `json:"username"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Orgs []OrgRecord `json:"orgs"`
|
Orgs []OrgRecord `json:"orgs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,10 +70,10 @@ func (s *SocialGrafanaNet) UserInfo(client *http.Client) (*BasicUserInfo, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
userInfo := &BasicUserInfo{
|
userInfo := &BasicUserInfo{
|
||||||
Name: data.Name,
|
Name: data.Name,
|
||||||
Login: data.Login,
|
Login: data.Login,
|
||||||
Email: data.Email,
|
Email: data.Email,
|
||||||
Role: data.Role,
|
Role: data.Role,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.IsOrganizationMember(data.Orgs) {
|
if !s.IsOrganizationMember(data.Orgs) {
|
||||||
|
@ -11,11 +11,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type BasicUserInfo struct {
|
type BasicUserInfo struct {
|
||||||
Name string
|
Name string
|
||||||
Email string
|
Email string
|
||||||
Login string
|
Login string
|
||||||
Company string
|
Company string
|
||||||
Role string
|
Role string
|
||||||
}
|
}
|
||||||
|
|
||||||
type SocialConnector interface {
|
type SocialConnector interface {
|
||||||
@ -91,11 +91,11 @@ func NewOAuthService() {
|
|||||||
// Google.
|
// Google.
|
||||||
if name == "google" {
|
if name == "google" {
|
||||||
SocialMap["google"] = &SocialGoogle{
|
SocialMap["google"] = &SocialGoogle{
|
||||||
Config: &config,
|
Config: &config,
|
||||||
allowedDomains: info.AllowedDomains,
|
allowedDomains: info.AllowedDomains,
|
||||||
hostedDomain: info.HostedDomain,
|
hostedDomain: info.HostedDomain,
|
||||||
apiUrl: info.ApiUrl,
|
apiUrl: info.ApiUrl,
|
||||||
allowSignup: info.AllowSignup,
|
allowSignup: info.AllowSignup,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,12 +115,12 @@ func NewOAuthService() {
|
|||||||
config = oauth2.Config{
|
config = oauth2.Config{
|
||||||
ClientID: info.ClientId,
|
ClientID: info.ClientId,
|
||||||
ClientSecret: info.ClientSecret,
|
ClientSecret: info.ClientSecret,
|
||||||
Endpoint: oauth2.Endpoint{
|
Endpoint: oauth2.Endpoint{
|
||||||
AuthURL: setting.GrafanaNetUrl + "/oauth2/authorize",
|
AuthURL: setting.GrafanaNetUrl + "/oauth2/authorize",
|
||||||
TokenURL: setting.GrafanaNetUrl + "/api/oauth2/token",
|
TokenURL: setting.GrafanaNetUrl + "/api/oauth2/token",
|
||||||
},
|
},
|
||||||
RedirectURL: strings.TrimSuffix(setting.AppUrl, "/") + SocialBaseUrl + name,
|
RedirectURL: strings.TrimSuffix(setting.AppUrl, "/") + SocialBaseUrl + name,
|
||||||
Scopes: info.Scopes,
|
Scopes: info.Scopes,
|
||||||
}
|
}
|
||||||
|
|
||||||
SocialMap["grafananet"] = &SocialGrafanaNet{
|
SocialMap["grafananet"] = &SocialGrafanaNet{
|
||||||
|
@ -3,9 +3,9 @@ package opentsdb
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/tsdb"
|
"github.com/grafana/grafana/pkg/tsdb"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOpenTsdbExecutor(t *testing.T) {
|
func TestOpenTsdbExecutor(t *testing.T) {
|
||||||
@ -23,8 +23,8 @@ func TestOpenTsdbExecutor(t *testing.T) {
|
|||||||
query.Model.Set("aggregator", "avg")
|
query.Model.Set("aggregator", "avg")
|
||||||
query.Model.Set("disableDownsampling", false)
|
query.Model.Set("disableDownsampling", false)
|
||||||
query.Model.Set("downsampleInterval", "")
|
query.Model.Set("downsampleInterval", "")
|
||||||
query.Model.Set("downsampleAggregator","avg")
|
query.Model.Set("downsampleAggregator", "avg")
|
||||||
query.Model.Set("downsampleFillPolicy","none")
|
query.Model.Set("downsampleFillPolicy", "none")
|
||||||
|
|
||||||
metric := exec.buildMetric(query)
|
metric := exec.buildMetric(query)
|
||||||
|
|
||||||
@ -45,8 +45,8 @@ func TestOpenTsdbExecutor(t *testing.T) {
|
|||||||
query.Model.Set("aggregator", "avg")
|
query.Model.Set("aggregator", "avg")
|
||||||
query.Model.Set("disableDownsampling", true)
|
query.Model.Set("disableDownsampling", true)
|
||||||
query.Model.Set("downsampleInterval", "")
|
query.Model.Set("downsampleInterval", "")
|
||||||
query.Model.Set("downsampleAggregator","avg")
|
query.Model.Set("downsampleAggregator", "avg")
|
||||||
query.Model.Set("downsampleFillPolicy","none")
|
query.Model.Set("downsampleFillPolicy", "none")
|
||||||
|
|
||||||
metric := exec.buildMetric(query)
|
metric := exec.buildMetric(query)
|
||||||
|
|
||||||
@ -66,8 +66,8 @@ func TestOpenTsdbExecutor(t *testing.T) {
|
|||||||
query.Model.Set("aggregator", "avg")
|
query.Model.Set("aggregator", "avg")
|
||||||
query.Model.Set("disableDownsampling", false)
|
query.Model.Set("disableDownsampling", false)
|
||||||
query.Model.Set("downsampleInterval", "5m")
|
query.Model.Set("downsampleInterval", "5m")
|
||||||
query.Model.Set("downsampleAggregator","sum")
|
query.Model.Set("downsampleAggregator", "sum")
|
||||||
query.Model.Set("downsampleFillPolicy","null")
|
query.Model.Set("downsampleFillPolicy", "null")
|
||||||
|
|
||||||
metric := exec.buildMetric(query)
|
metric := exec.buildMetric(query)
|
||||||
|
|
||||||
@ -87,8 +87,8 @@ func TestOpenTsdbExecutor(t *testing.T) {
|
|||||||
query.Model.Set("aggregator", "avg")
|
query.Model.Set("aggregator", "avg")
|
||||||
query.Model.Set("disableDownsampling", true)
|
query.Model.Set("disableDownsampling", true)
|
||||||
query.Model.Set("downsampleInterval", "5m")
|
query.Model.Set("downsampleInterval", "5m")
|
||||||
query.Model.Set("downsampleAggregator","sum")
|
query.Model.Set("downsampleAggregator", "sum")
|
||||||
query.Model.Set("downsampleFillPolicy","null")
|
query.Model.Set("downsampleFillPolicy", "null")
|
||||||
|
|
||||||
tags := simplejson.New()
|
tags := simplejson.New()
|
||||||
tags.Set("env", "prod")
|
tags.Set("env", "prod")
|
||||||
@ -117,7 +117,7 @@ func TestOpenTsdbExecutor(t *testing.T) {
|
|||||||
query.Model.Set("aggregator", "avg")
|
query.Model.Set("aggregator", "avg")
|
||||||
query.Model.Set("disableDownsampling", true)
|
query.Model.Set("disableDownsampling", true)
|
||||||
query.Model.Set("shouldComputeRate", true)
|
query.Model.Set("shouldComputeRate", true)
|
||||||
query.Model.Set("isCounter",false)
|
query.Model.Set("isCounter", false)
|
||||||
|
|
||||||
tags := simplejson.New()
|
tags := simplejson.New()
|
||||||
tags.Set("env", "prod")
|
tags.Set("env", "prod")
|
||||||
@ -147,9 +147,9 @@ func TestOpenTsdbExecutor(t *testing.T) {
|
|||||||
query.Model.Set("aggregator", "avg")
|
query.Model.Set("aggregator", "avg")
|
||||||
query.Model.Set("disableDownsampling", true)
|
query.Model.Set("disableDownsampling", true)
|
||||||
query.Model.Set("shouldComputeRate", true)
|
query.Model.Set("shouldComputeRate", true)
|
||||||
query.Model.Set("isCounter",true)
|
query.Model.Set("isCounter", true)
|
||||||
query.Model.Set("counterMax",45)
|
query.Model.Set("counterMax", 45)
|
||||||
query.Model.Set("counterResetValue",60)
|
query.Model.Set("counterResetValue", 60)
|
||||||
|
|
||||||
tags := simplejson.New()
|
tags := simplejson.New()
|
||||||
tags.Set("env", "prod")
|
tags.Set("env", "prod")
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package opentsdb
|
package opentsdb
|
||||||
|
|
||||||
type OpenTsdbQuery struct {
|
type OpenTsdbQuery struct {
|
||||||
Start int64 `json:"start"`
|
Start int64 `json:"start"`
|
||||||
End int64 `json:"end"`
|
End int64 `json:"end"`
|
||||||
Queries []map[string]interface{} `json:"queries"`
|
Queries []map[string]interface{} `json:"queries"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenTsdbResponse struct {
|
type OpenTsdbResponse struct {
|
||||||
Metric string `json:"metric"`
|
Metric string `json:"metric"`
|
||||||
DataPoints map[string]float64 `json:"dps"`
|
DataPoints map[string]float64 `json:"dps"`
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user