models.go 3.0 KB

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