user.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. Email string `json:"email" gorm:"unique"`
  9. Password string `json:"password"`
  10. Clusters []ClusterConfig `json:"clusters"`
  11. RawKubeConfig []byte `json:"rawKubeConfig"`
  12. }
  13. // UserExternal represents the User type that is sent over REST
  14. type UserExternal struct {
  15. ID uint `json:"id"`
  16. Email string `json:"email"`
  17. Clusters []*ClusterConfigExternal `json:"clusters"`
  18. RawKubeConfig string `json:"rawKubeConfig"`
  19. }
  20. // Externalize generates an external User to be shared over REST
  21. func (u *User) Externalize() *UserExternal {
  22. clustersExt := make([]*ClusterConfigExternal, 0)
  23. for _, cluster := range u.Clusters {
  24. clustersExt = append(clustersExt, cluster.Externalize())
  25. }
  26. return &UserExternal{
  27. ID: u.ID,
  28. Email: u.Email,
  29. Clusters: clustersExt,
  30. RawKubeConfig: string(u.RawKubeConfig),
  31. }
  32. }