models.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package dtos
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "strings"
  6. "time"
  7. m "github.com/grafana/grafana/pkg/models"
  8. )
  9. type LoginCommand struct {
  10. User string `json:"user" binding:"Required"`
  11. Password string `json:"password" binding:"Required"`
  12. Remember bool `json:"remember"`
  13. }
  14. type CurrentUser struct {
  15. IsSignedIn bool `json:"isSignedIn"`
  16. Id int64 `json:"id"`
  17. Login string `json:"login"`
  18. Email string `json:"email"`
  19. Name string `json:"name"`
  20. LightTheme bool `json:"lightTheme"`
  21. OrgId int64 `json:"orgId"`
  22. OrgName string `json:"orgName"`
  23. OrgRole m.RoleType `json:"orgRole"`
  24. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  25. GravatarUrl string `json:"gravatarUrl"`
  26. }
  27. type DashboardMeta struct {
  28. IsStarred bool `json:"isStarred,omitempty"`
  29. IsHome bool `json:"isHome,omitempty"`
  30. IsSnapshot bool `json:"isSnapshot,omitempty"`
  31. Type string `json:"type,omitempty"`
  32. CanSave bool `json:"canSave"`
  33. CanEdit bool `json:"canEdit"`
  34. CanStar bool `json:"canStar"`
  35. Slug string `json:"slug"`
  36. Expires time.Time `json:"expires"`
  37. Created time.Time `json:"created"`
  38. Updated time.Time `json:"updated"`
  39. UpdatedBy string `json:"updatedBy"`
  40. CreatedBy string `json:"createdBy"`
  41. TotalRows int `json:"totalRows"`
  42. TotalPanels int `json:"totalPanels"`
  43. TotalQueries int `json:"totalQueries"`
  44. Version int `json:"version"`
  45. }
  46. type DashboardFullWithMeta struct {
  47. Meta DashboardMeta `json:"meta"`
  48. Dashboard map[string]interface{} `json:"dashboard"`
  49. }
  50. type DataSource struct {
  51. Id int64 `json:"id"`
  52. OrgId int64 `json:"orgId"`
  53. Name string `json:"name"`
  54. Type string `json:"type"`
  55. Access m.DsAccess `json:"access"`
  56. Url string `json:"url"`
  57. Password string `json:"password"`
  58. User string `json:"user"`
  59. Database string `json:"database"`
  60. BasicAuth bool `json:"basicAuth"`
  61. BasicAuthUser string `json:"basicAuthUser"`
  62. BasicAuthPassword string `json:"basicAuthPassword"`
  63. WithCredentials bool `json:"withCredentials"`
  64. IsDefault bool `json:"isDefault"`
  65. JsonData map[string]interface{} `json:"jsonData,omitempty"`
  66. }
  67. type MetricQueryResultDto struct {
  68. Data []MetricQueryResultDataDto `json:"data"`
  69. }
  70. type MetricQueryResultDataDto struct {
  71. Target string `json:"target"`
  72. DataPoints [][2]float64 `json:"datapoints"`
  73. }
  74. type UserStars struct {
  75. DashboardIds map[string]bool `json:"dashboardIds"`
  76. }
  77. func GetGravatarUrl(text string) string {
  78. if text == "" {
  79. return ""
  80. }
  81. hasher := md5.New()
  82. hasher.Write([]byte(strings.ToLower(text)))
  83. return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=90&default=mm", hasher.Sum(nil))
  84. }