mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 12:14:08 -06:00
fa7d7ed5df
* wip: start on refactoring settings * settings: progress on settings refactor * refactor: progress on settings refactoring * fix: fixed failing test * settings: moved smtp settings from global to instance
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
func AdminGetSettings(c *m.ReqContext) {
|
|
settings := make(map[string]interface{})
|
|
|
|
for _, section := range setting.Raw.Sections() {
|
|
jsonSec := make(map[string]interface{})
|
|
settings[section.Name()] = jsonSec
|
|
|
|
for _, key := range section.Keys() {
|
|
keyName := key.Name()
|
|
value := key.Value()
|
|
if strings.Contains(keyName, "secret") || strings.Contains(keyName, "password") || (strings.Contains(keyName, "provider_config")) {
|
|
value = "************"
|
|
}
|
|
if strings.Contains(keyName, "url") {
|
|
var rgx = regexp.MustCompile(`.*:\/\/([^:]*):([^@]*)@.*?$`)
|
|
var subs = rgx.FindAllSubmatch([]byte(value), -1)
|
|
if subs != nil && len(subs[0]) == 3 {
|
|
value = strings.Replace(value, string(subs[0][1]), "******", 1)
|
|
value = strings.Replace(value, string(subs[0][2]), "******", 1)
|
|
}
|
|
}
|
|
|
|
jsonSec[keyName] = value
|
|
}
|
|
}
|
|
|
|
c.JSON(200, settings)
|
|
}
|
|
|
|
func AdminGetStats(c *m.ReqContext) {
|
|
|
|
statsQuery := m.GetAdminStatsQuery{}
|
|
|
|
if err := bus.Dispatch(&statsQuery); err != nil {
|
|
c.JsonApiErr(500, "Failed to get admin stats from database", err)
|
|
return
|
|
}
|
|
|
|
c.JSON(200, statsQuery.Result)
|
|
}
|