models.go 2.9 KB

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