project.go 1.5 KB

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