app_settings.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. "github.com/grafana/grafana/pkg/setting"
  6. "github.com/grafana/grafana/pkg/util"
  7. )
  8. var (
  9. ErrAppSettingNotFound = errors.New("AppSetting not found")
  10. )
  11. type AppSettings struct {
  12. Id int64
  13. AppId string
  14. OrgId int64
  15. Enabled bool
  16. Pinned bool
  17. JsonData map[string]interface{}
  18. SecureJsonData SecureJsonData
  19. Created time.Time
  20. Updated time.Time
  21. }
  22. type SecureJsonData map[string][]byte
  23. func (s SecureJsonData) Decrypt() map[string]string {
  24. decrypted := make(map[string]string)
  25. for key, data := range s {
  26. decrypted[key] = string(util.Decrypt(data, setting.SecretKey))
  27. }
  28. return decrypted
  29. }
  30. // ----------------------
  31. // COMMANDS
  32. // Also acts as api DTO
  33. type UpdateAppSettingsCmd struct {
  34. Enabled bool `json:"enabled"`
  35. Pinned bool `json:"pinned"`
  36. JsonData map[string]interface{} `json:"jsonData"`
  37. SecureJsonData map[string]string `json:"secureJsonData"`
  38. AppId string `json:"-"`
  39. OrgId int64 `json:"-"`
  40. }
  41. // ---------------------
  42. // QUERIES
  43. type GetAppSettingsQuery struct {
  44. OrgId int64
  45. Result []*AppSettings
  46. }
  47. type GetAppSettingByAppIdQuery struct {
  48. AppId string
  49. OrgId int64
  50. Result *AppSettings
  51. }