project.go 1.6 KB

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