mirror of https://github.com/grafana/grafana
parent
ce947d4793
commit
d69258e28f
@ -1 +1 @@ |
||||
Subproject commit ad91093902bdfc0d2a87bb362a76a9057aef4361 |
||||
Subproject commit 4e542d8b83844f8faa4d5ae3edab593950aaa344 |
||||
@ -0,0 +1,68 @@ |
||||
package api |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"strings" |
||||
|
||||
"github.com/torkelo/grafana-pro/pkg/bus" |
||||
"github.com/torkelo/grafana-pro/pkg/middleware" |
||||
m "github.com/torkelo/grafana-pro/pkg/models" |
||||
) |
||||
|
||||
const configTemplate = ` |
||||
define(['settings'], |
||||
function (Settings) { |
||||
"use strict"; |
||||
return new Settings(%json%); |
||||
}); |
||||
` |
||||
|
||||
type configJsTmplModel struct { |
||||
DataSources []*m.DataSource |
||||
} |
||||
|
||||
func renderConfig(data *configJsTmplModel) string { |
||||
datasources := make(map[string]interface{}) |
||||
|
||||
for _, ds := range data.DataSources { |
||||
datasources[ds.Name] = map[string]interface{}{ |
||||
"type": ds.Type, |
||||
"url": ds.Url, |
||||
} |
||||
} |
||||
|
||||
jsonObj := map[string]interface{}{ |
||||
"datasources": datasources, |
||||
} |
||||
|
||||
buff, _ := json.Marshal(jsonObj) |
||||
|
||||
return strings.Replace(configTemplate, "%json%", string(buff), 1) |
||||
} |
||||
|
||||
func GetConfigJS(c *middleware.Context) { |
||||
|
||||
query := m.GetDataSourcesQuery{AccountId: c.GetAccountId()} |
||||
err := bus.Dispatch(&query) |
||||
|
||||
if err != nil { |
||||
c.Handle(500, "cold not load data sources", err) |
||||
return |
||||
} |
||||
|
||||
vm := configJsTmplModel{DataSources: query.Result} |
||||
configStr := renderConfig(&vm) |
||||
|
||||
if err != nil { |
||||
c.Handle(500, "Failed to generate config.js", err) |
||||
return |
||||
} |
||||
|
||||
c.Header().Set("Content-Type", "text/javascript; charset=UTF-8") |
||||
c.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") |
||||
c.Header().Set("Pragma", "no-cache") |
||||
c.Header().Set("Expires", "0") |
||||
c.WriteHeader(200) |
||||
|
||||
c.Write([]byte(configStr)) |
||||
} |
||||
@ -1,40 +0,0 @@ |
||||
package configuration |
||||
|
||||
type Cfg struct { |
||||
Http HttpCfg |
||||
} |
||||
|
||||
type HttpCfg struct { |
||||
Port string |
||||
GoogleOAuth OAuthCfg |
||||
GithubOAuth OAuthCfg |
||||
} |
||||
|
||||
type OAuthCfg struct { |
||||
Enabled bool |
||||
ClientId string |
||||
ClientSecret string |
||||
} |
||||
|
||||
type DashboardSourceCfg struct { |
||||
sourceType string |
||||
path string |
||||
} |
||||
|
||||
func NewCfg(port string) *Cfg { |
||||
return &Cfg{ |
||||
Http: HttpCfg{ |
||||
Port: port, |
||||
GoogleOAuth: OAuthCfg{ |
||||
Enabled: true, |
||||
ClientId: "106011922963-4pvl05e9urtrm8bbqr0vouosj3e8p8kb.apps.googleusercontent.com", |
||||
ClientSecret: "K2evIa4QhfbhhAm3SO72t2Zv", |
||||
}, |
||||
GithubOAuth: OAuthCfg{ |
||||
Enabled: true, |
||||
ClientId: "de054205006b9baa2e17", |
||||
ClientSecret: "72b7ea52d9f1096fdf36cea95e95362a307e0322", |
||||
}, |
||||
}, |
||||
} |
||||
} |
||||
Loading…
Reference in new issue