models.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. }
  42. type DashboardFullWithMeta struct {
  43. Meta DashboardMeta `json:"meta"`
  44. Dashboard map[string]interface{} `json:"dashboard"`
  45. }
  46. type DataSource struct {
  47. Id int64 `json:"id"`
  48. OrgId int64 `json:"orgId"`
  49. Name string `json:"name"`
  50. Type string `json:"type"`
  51. Access m.DsAccess `json:"access"`
  52. Url string `json:"url"`
  53. Password string `json:"password"`
  54. User string `json:"user"`
  55. Database string `json:"database"`
  56. BasicAuth bool `json:"basicAuth"`
  57. BasicAuthUser string `json:"basicAuthUser"`
  58. BasicAuthPassword string `json:"basicAuthPassword"`
  59. WithCredentials bool `json:"withCredentials"`
  60. IsDefault bool `json:"isDefault"`
  61. JsonData map[string]interface{} `json:"jsonData,omitempty"`
  62. }
  63. type MetricQueryResultDto struct {
  64. Data []MetricQueryResultDataDto `json:"data"`
  65. }
  66. type MetricQueryResultDataDto struct {
  67. Target string `json:"target"`
  68. DataPoints [][2]float64 `json:"datapoints"`
  69. }
  70. type UserStars struct {
  71. DashboardIds map[string]bool `json:"dashboardIds"`
  72. }
  73. func GetGravatarUrl(text string) string {
  74. if text == "" {
  75. return ""
  76. }
  77. hasher := md5.New()
  78. hasher.Write([]byte(strings.ToLower(text)))
  79. return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=90&default=mm", hasher.Sum(nil))
  80. }