2
0

project.go 1.8 KB

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