project.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. GitRepos []GitRepoExternal `json:"git_repos,omitempty"`
  37. }
  38. // Externalize generates an external Project to be shared over REST
  39. func (p *Project) Externalize() *ProjectExternal {
  40. repos := make([]GitRepoExternal, 0)
  41. for _, repo := range p.GitRepos {
  42. repos = append(repos, *repo.Externalize())
  43. }
  44. return &ProjectExternal{
  45. ID: p.ID,
  46. Name: p.Name,
  47. GitRepos: repos,
  48. }
  49. }