models.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package dtos
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "strings"
  6. "github.com/grafana/grafana/pkg/components/simplejson"
  7. m "github.com/grafana/grafana/pkg/models"
  8. "github.com/grafana/grafana/pkg/setting"
  9. )
  10. type AnyId struct {
  11. Id int64 `json:"id"`
  12. }
  13. type LoginCommand struct {
  14. User string `json:"user" binding:"Required"`
  15. Password string `json:"password" binding:"Required"`
  16. Remember bool `json:"remember"`
  17. }
  18. type CurrentUser struct {
  19. IsSignedIn bool `json:"isSignedIn"`
  20. Id int64 `json:"id"`
  21. Login string `json:"login"`
  22. Email string `json:"email"`
  23. Name string `json:"name"`
  24. LightTheme bool `json:"lightTheme"`
  25. OrgId int64 `json:"orgId"`
  26. OrgName string `json:"orgName"`
  27. OrgRole m.RoleType `json:"orgRole"`
  28. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  29. GravatarUrl string `json:"gravatarUrl"`
  30. Timezone string `json:"timezone"`
  31. Locale string `json:"locale"`
  32. HelpFlags1 m.HelpFlags1 `json:"helpFlags1"`
  33. }
  34. type DataSource struct {
  35. Id int64 `json:"id"`
  36. OrgId int64 `json:"orgId"`
  37. Name string `json:"name"`
  38. Type string `json:"type"`
  39. TypeLogoUrl string `json:"typeLogoUrl"`
  40. Access m.DsAccess `json:"access"`
  41. Url string `json:"url"`
  42. Password string `json:"password"`
  43. User string `json:"user"`
  44. Database string `json:"database"`
  45. BasicAuth bool `json:"basicAuth"`
  46. BasicAuthUser string `json:"basicAuthUser"`
  47. BasicAuthPassword string `json:"basicAuthPassword"`
  48. WithCredentials bool `json:"withCredentials"`
  49. IsDefault bool `json:"isDefault"`
  50. JsonData *simplejson.Json `json:"jsonData,omitempty"`
  51. SecureJsonFields map[string]bool `json:"secureJsonFields"`
  52. }
  53. type DataSourceListItemDTO struct {
  54. Id int64 `json:"id"`
  55. OrgId int64 `json:"orgId"`
  56. Name string `json:"name"`
  57. Type string `json:"type"`
  58. TypeLogoUrl string `json:"typeLogoUrl"`
  59. Access m.DsAccess `json:"access"`
  60. Url string `json:"url"`
  61. Password string `json:"password"`
  62. User string `json:"user"`
  63. Database string `json:"database"`
  64. BasicAuth bool `json:"basicAuth"`
  65. IsDefault bool `json:"isDefault"`
  66. JsonData *simplejson.Json `json:"jsonData,omitempty"`
  67. }
  68. type DataSourceList []DataSourceListItemDTO
  69. func (slice DataSourceList) Len() int {
  70. return len(slice)
  71. }
  72. func (slice DataSourceList) Less(i, j int) bool {
  73. return strings.ToLower(slice[i].Name) < strings.ToLower(slice[j].Name)
  74. }
  75. func (slice DataSourceList) Swap(i, j int) {
  76. slice[i], slice[j] = slice[j], slice[i]
  77. }
  78. type MetricRequest struct {
  79. From string `json:"from"`
  80. To string `json:"to"`
  81. Queries []*simplejson.Json `json:"queries"`
  82. }
  83. type UserStars struct {
  84. DashboardIds map[string]bool `json:"dashboardIds"`
  85. }
  86. func GetGravatarUrl(text string) string {
  87. if text == "" {
  88. return ""
  89. }
  90. hasher := md5.New()
  91. hasher.Write([]byte(strings.ToLower(text)))
  92. return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
  93. }