project.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // auth mechanisms
  21. KubeIntegrations []ints.KubeIntegration `json:"kube_integrations"`
  22. BasicIntegrations []ints.BasicIntegration `json:"basic_integrations"`
  23. OIDCIntegrations []ints.OIDCIntegration `json:"oidc_integrations"`
  24. OAuthIntegrations []ints.OAuthIntegration `json:"oauth_integrations"`
  25. AWSIntegrations []ints.AWSIntegration `json:"aws_integrations"`
  26. GCPIntegrations []ints.GCPIntegration `json:"gcp_integrations"`
  27. }
  28. // ProjectExternal represents the Project type that is sent over REST
  29. type ProjectExternal struct {
  30. ID uint `json:"id"`
  31. Name string `json:"name"`
  32. Roles []RoleExternal `json:"roles"`
  33. GitRepos []GitRepoExternal `json:"git_repos,omitempty"`
  34. }
  35. // Externalize generates an external Project to be shared over REST
  36. func (p *Project) Externalize() *ProjectExternal {
  37. roles := make([]RoleExternal, 0)
  38. for _, role := range p.Roles {
  39. roles = append(roles, *role.Externalize())
  40. }
  41. repos := make([]GitRepoExternal, 0)
  42. for _, repo := range p.GitRepos {
  43. repos = append(repos, *repo.Externalize())
  44. }
  45. return &ProjectExternal{
  46. ID: p.ID,
  47. Name: p.Name,
  48. Roles: roles,
  49. GitRepos: repos,
  50. }
  51. }