models.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package dtos
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "strings"
  6. "github.com/torkelo/grafana-pro/pkg/models"
  7. )
  8. type LoginResult struct {
  9. Status string `json:"status"`
  10. User CurrentUser `json:"user"`
  11. }
  12. type CurrentUser struct {
  13. Login string `json:"login"`
  14. Email string `json:"email"`
  15. GravatarUrl string `json:"gravatarUrl"`
  16. }
  17. type AccountInfo struct {
  18. Email string `json:"email"`
  19. Name string `json:"name"`
  20. Collaborators []*Collaborator `json:"collaborators"`
  21. }
  22. type OtherAccount struct {
  23. Id int64 `json:"id"`
  24. Name string `json:"name"`
  25. Role string `json:"role"`
  26. IsUsing bool `json:"isUsing"`
  27. }
  28. type Collaborator struct {
  29. AccountId int64 `json:"accountId"`
  30. Email string `json:"email"`
  31. Role string `json:"role"`
  32. }
  33. type DataSource struct {
  34. Id int64 `json:"id"`
  35. AccountId int64 `json:"accountId"`
  36. Name string `json:"name"`
  37. Type models.DsType `json:"type"`
  38. Access models.DsAccess `json:"access"`
  39. Url string `json:"url"`
  40. Password string `json:"password"`
  41. User string `json:"user"`
  42. BasicAuth bool `json:"basicAuth"`
  43. }
  44. func NewCurrentUser(account *models.Account) *CurrentUser {
  45. model := &CurrentUser{}
  46. if account != nil {
  47. model.Login = account.Login
  48. model.Email = account.Email
  49. model.GravatarUrl = getGravatarUrl(account.Email)
  50. }
  51. return model
  52. }
  53. func getGravatarUrl(text string) string {
  54. hasher := md5.New()
  55. hasher.Write([]byte(strings.ToLower(text)))
  56. return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=90&default=mm", hasher.Sum(nil))
  57. }