models.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package dtos
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "strings"
  6. "time"
  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. }
  31. type DashboardMeta struct {
  32. IsStarred bool `json:"isStarred,omitempty"`
  33. IsHome bool `json:"isHome,omitempty"`
  34. IsSnapshot bool `json:"isSnapshot,omitempty"`
  35. Type string `json:"type,omitempty"`
  36. CanSave bool `json:"canSave"`
  37. CanEdit bool `json:"canEdit"`
  38. CanStar bool `json:"canStar"`
  39. Slug string `json:"slug"`
  40. Expires time.Time `json:"expires"`
  41. Created time.Time `json:"created"`
  42. Updated time.Time `json:"updated"`
  43. UpdatedBy string `json:"updatedBy"`
  44. CreatedBy string `json:"createdBy"`
  45. Version int `json:"version"`
  46. }
  47. type DashboardFullWithMeta struct {
  48. Meta DashboardMeta `json:"meta"`
  49. Dashboard map[string]interface{} `json:"dashboard"`
  50. }
  51. type DataSource struct {
  52. Id int64 `json:"id"`
  53. OrgId int64 `json:"orgId"`
  54. Name string `json:"name"`
  55. Type string `json:"type"`
  56. Access m.DsAccess `json:"access"`
  57. Url string `json:"url"`
  58. Password string `json:"password"`
  59. User string `json:"user"`
  60. Database string `json:"database"`
  61. BasicAuth bool `json:"basicAuth"`
  62. BasicAuthUser string `json:"basicAuthUser"`
  63. BasicAuthPassword string `json:"basicAuthPassword"`
  64. WithCredentials bool `json:"withCredentials"`
  65. IsDefault bool `json:"isDefault"`
  66. JsonData map[string]interface{} `json:"jsonData,omitempty"`
  67. }
  68. type MetricQueryResultDto struct {
  69. Data []MetricQueryResultDataDto `json:"data"`
  70. }
  71. type MetricQueryResultDataDto struct {
  72. Target string `json:"target"`
  73. DataPoints [][2]float64 `json:"datapoints"`
  74. }
  75. type UserStars struct {
  76. DashboardIds map[string]bool `json:"dashboardIds"`
  77. }
  78. func GetGravatarUrl(text string) string {
  79. if text == "" {
  80. return ""
  81. }
  82. hasher := md5.New()
  83. hasher.Write([]byte(strings.ToLower(text)))
  84. return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
  85. }