user.go 1.1 KB

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