project.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package models
  2. import (
  3. "gorm.io/gorm"
  4. ints "github.com/porter-dev/porter/internal/models/integrations"
  5. )
  6. // Project type that extends gorm.Model
  7. type Project struct {
  8. gorm.Model
  9. Name string `json:"name"`
  10. Roles []Role `json:"roles"`
  11. // linked repos
  12. GitRepos []GitRepo `json:"git_repos,omitempty"`
  13. // linked registries
  14. Registries []Registry `json:"registries,omitempty"`
  15. // linked clusters
  16. Clusters []Cluster `json:"clusters"`
  17. ClusterCandidates []ClusterCandidate `json:"cluster_candidates"`
  18. // linked helm repos
  19. HelmRepos []HelmRepo `json:"helm_repos"`
  20. // invitations to the project
  21. Invites []Invite `json:"invites"`
  22. // provisioned aws infra
  23. Infras []Infra `json:"infras"`
  24. // auth mechanisms
  25. KubeIntegrations []ints.KubeIntegration `json:"kube_integrations"`
  26. BasicIntegrations []ints.BasicIntegration `json:"basic_integrations"`
  27. OIDCIntegrations []ints.OIDCIntegration `json:"oidc_integrations"`
  28. OAuthIntegrations []ints.OAuthIntegration `json:"oauth_integrations"`
  29. AWSIntegrations []ints.AWSIntegration `json:"aws_integrations"`
  30. GCPIntegrations []ints.GCPIntegration `json:"gcp_integrations"`
  31. }
  32. // ProjectExternal represents the Project type that is sent over REST
  33. type ProjectExternal struct {
  34. ID uint `json:"id"`
  35. Name string `json:"name"`
  36. Roles []RoleExternal `json:"roles"`
  37. GitRepos []GitRepoExternal `json:"git_repos,omitempty"`
  38. }
  39. // Externalize generates an external Project to be shared over REST
  40. func (p *Project) Externalize() *ProjectExternal {
  41. roles := make([]RoleExternal, 0)
  42. for _, role := range p.Roles {
  43. roles = append(roles, *role.Externalize())
  44. }
  45. repos := make([]GitRepoExternal, 0)
  46. for _, repo := range p.GitRepos {
  47. repos = append(repos, *repo.Externalize())
  48. }
  49. return &ProjectExternal{
  50. ID: p.ID,
  51. Name: p.Name,
  52. Roles: roles,
  53. GitRepos: repos,
  54. }
  55. }