user.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package models
  2. import (
  3. "github.com/jinzhu/gorm"
  4. )
  5. // User type that extends gorm.Model
  6. type User struct {
  7. gorm.Model
  8. // Unique email for each user
  9. Email,
  10. // Hashed password
  11. Password string
  12. // The clusters that this user has linked
  13. Clusters []ClusterConfig
  14. // The raw kubeconfig uploaded by this user
  15. RawKubeConfig []byte
  16. }
  17. // UserExternal represents the User type that is sent over REST
  18. type UserExternal struct {
  19. ID uint `json:"id"`
  20. Email string `json:"email"`
  21. Clusters []*ClusterConfigExternal `json:"clusters"`
  22. RawKubeConfig string `json:"rawKubeConfig"`
  23. }
  24. // Externalize generates an external User to be shared over REST
  25. func (u *User) Externalize() *UserExternal {
  26. clustersExt := make([]*ClusterConfigExternal, 0)
  27. for _, cluster := range u.Clusters {
  28. clustersExt = append(clustersExt, cluster.Externalize())
  29. }
  30. return &UserExternal{
  31. ID: u.ID,
  32. Email: u.Email,
  33. Clusters: clustersExt,
  34. RawKubeConfig: string(u.RawKubeConfig),
  35. }
  36. }