mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 09:03:11 +08:00
API: Use SettingsProvider on GET settings handler (#34632)
This commit is contained in:

committed by
GitHub

parent
881abb3af8
commit
b74a502dc4
@ -4,23 +4,10 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/api/response"
|
"github.com/grafana/grafana/pkg/api/response"
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func AdminGetSettings(c *models.ReqContext) response.Response {
|
func (hs *HTTPServer) AdminGetSettings(_ *models.ReqContext) response.Response {
|
||||||
settings := make(map[string]interface{})
|
return response.JSON(200, hs.SettingsProvider.Current())
|
||||||
|
|
||||||
for _, section := range setting.Raw.Sections() {
|
|
||||||
jsonSec := make(map[string]interface{})
|
|
||||||
settings[section.Name()] = jsonSec
|
|
||||||
|
|
||||||
for _, key := range section.Keys() {
|
|
||||||
keyName := key.Name()
|
|
||||||
jsonSec[keyName] = setting.RedactedValue(keyName, key.Value())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.JSON(200, settings)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AdminGetStats(c *models.ReqContext) response.Response {
|
func AdminGetStats(c *models.ReqContext) response.Response {
|
||||||
|
@ -440,7 +440,7 @@ func (hs *HTTPServer) registerRoutes() {
|
|||||||
|
|
||||||
// admin api
|
// admin api
|
||||||
r.Group("/api/admin", func(adminRoute routing.RouteRegister) {
|
r.Group("/api/admin", func(adminRoute routing.RouteRegister) {
|
||||||
adminRoute.Get("/settings", reqGrafanaAdmin, routing.Wrap(AdminGetSettings))
|
adminRoute.Get("/settings", reqGrafanaAdmin, routing.Wrap(hs.AdminGetSettings))
|
||||||
adminRoute.Get("/stats", reqGrafanaAdmin, routing.Wrap(AdminGetStats))
|
adminRoute.Get("/stats", reqGrafanaAdmin, routing.Wrap(AdminGetStats))
|
||||||
adminRoute.Post("/pause-all-alerts", reqGrafanaAdmin, bind(dtos.PauseAllAlertsCommand{}), routing.Wrap(PauseAllAlerts))
|
adminRoute.Post("/pause-all-alerts", reqGrafanaAdmin, bind(dtos.PauseAllAlertsCommand{}), routing.Wrap(PauseAllAlerts))
|
||||||
|
|
||||||
|
@ -32,7 +32,13 @@ func (v ValidationError) Error() string {
|
|||||||
// Provider is a settings provider abstraction
|
// Provider is a settings provider abstraction
|
||||||
// with thread-safety and runtime updates.
|
// with thread-safety and runtime updates.
|
||||||
type Provider interface {
|
type Provider interface {
|
||||||
// Update
|
// Current returns a SettingsBag with a static copy of
|
||||||
|
// the current configured pairs of key/values for each
|
||||||
|
// configuration section.
|
||||||
|
Current() SettingsBag
|
||||||
|
// Update receives a SettingsBag with the pairs of key/values
|
||||||
|
// to be updated per section and a SettingsRemovals with the
|
||||||
|
// section keys to be removed.
|
||||||
Update(updates SettingsBag, removals SettingsRemovals) error
|
Update(updates SettingsBag, removals SettingsRemovals) error
|
||||||
// KeyValue returns a key-value abstraction
|
// KeyValue returns a key-value abstraction
|
||||||
// for the given pair of section and key.
|
// for the given pair of section and key.
|
||||||
@ -94,6 +100,19 @@ func (o OSSImpl) Init() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o OSSImpl) Current() SettingsBag {
|
||||||
|
settingsCopy := make(SettingsBag)
|
||||||
|
|
||||||
|
for _, section := range o.Cfg.Raw.Sections() {
|
||||||
|
settingsCopy[section.Name()] = make(map[string]string)
|
||||||
|
for _, key := range section.Keys() {
|
||||||
|
settingsCopy[section.Name()][key.Name()] = RedactedValue(key.Name(), key.Value())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return settingsCopy
|
||||||
|
}
|
||||||
|
|
||||||
func (OSSImpl) Update(SettingsBag, SettingsRemovals) error {
|
func (OSSImpl) Update(SettingsBag, SettingsRemovals) error {
|
||||||
return errors.New("oss settings provider do not have support for settings updates")
|
return errors.New("oss settings provider do not have support for settings updates")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user