repoclient.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package models
  2. import (
  3. "gorm.io/gorm"
  4. )
  5. // The allowed repository clients
  6. const (
  7. RepoClientGithub = "github"
  8. )
  9. // RepoClient is a client for a set of repositories that has been added
  10. // via a project OAuth flow
  11. type RepoClient struct {
  12. gorm.Model
  13. ProjectID uint `json:"project_id"`
  14. UserID uint `json:"user_id"`
  15. RepoUserID uint `json:"repo_id"`
  16. // the kind can be one of the predefined repo kinds
  17. Kind string `json:"kind"`
  18. // ------------------------------------------------------------------
  19. // All fields below this line are encrypted before storage
  20. // ------------------------------------------------------------------
  21. AccessToken string `json:"access_token"`
  22. RefreshToken string `json:"refresh_token"`
  23. }
  24. // RepoClientExternal is a RepoClient scrubbed of sensitive information to be
  25. // shared over REST
  26. type RepoClientExternal struct {
  27. ID uint `json:"id"`
  28. ProjectID uint `json:"project_id"`
  29. UserID uint `json:"user_id"`
  30. RepoUserID uint `json:"repo_id"`
  31. Kind string `json:"kind"`
  32. }
  33. // Externalize generates an external RepoClient to be shared over REST
  34. func (r *RepoClient) Externalize() *RepoClientExternal {
  35. return &RepoClientExternal{
  36. ID: r.Model.ID,
  37. ProjectID: r.ProjectID,
  38. UserID: r.UserID,
  39. RepoUserID: r.RepoUserID,
  40. Kind: r.Kind,
  41. }
  42. }