project.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package models
  2. import (
  3. "gorm.io/gorm"
  4. "github.com/porter-dev/porter/api/types"
  5. ints "github.com/porter-dev/porter/internal/models/integrations"
  6. )
  7. // Project type that extends gorm.Model
  8. type Project struct {
  9. gorm.Model
  10. Name string `json:"name"`
  11. Roles []Role `json:"roles"`
  12. // linked repos
  13. GitRepos []GitRepo `json:"git_repos,omitempty"`
  14. // linked registries
  15. Registries []Registry `json:"registries,omitempty"`
  16. // linked clusters
  17. Clusters []Cluster `json:"clusters"`
  18. ClusterCandidates []ClusterCandidate `json:"cluster_candidates"`
  19. // linked helm repos
  20. HelmRepos []HelmRepo `json:"helm_repos"`
  21. // invitations to the project
  22. Invites []Invite `json:"invites"`
  23. // provisioned aws infra
  24. Infras []Infra `json:"infras"`
  25. // auth mechanisms
  26. KubeIntegrations []ints.KubeIntegration `json:"kube_integrations"`
  27. BasicIntegrations []ints.BasicIntegration `json:"basic_integrations"`
  28. OIDCIntegrations []ints.OIDCIntegration `json:"oidc_integrations"`
  29. OAuthIntegrations []ints.OAuthIntegration `json:"oauth_integrations"`
  30. AWSIntegrations []ints.AWSIntegration `json:"aws_integrations"`
  31. GCPIntegrations []ints.GCPIntegration `json:"gcp_integrations"`
  32. }
  33. // // ProjectExternal represents the Project type that is sent over REST
  34. // type ProjectExternal struct {
  35. // ID uint `json:"id"`
  36. // Name string `json:"name"`
  37. // GitRepos []GitRepoExternal `json:"git_repos,omitempty"`
  38. // }
  39. // // Externalize generates an external Project to be shared over REST
  40. // func (p *Project) Externalize() *ProjectExternal {
  41. // roles := make([]RoleExternal, 0)
  42. // for _, role := range p.Roles {
  43. // roles = append(roles, *role.Externalize())
  44. // }
  45. // return &ProjectExternal{
  46. // ID: p.ID,
  47. // Name: p.Name,
  48. // Roles: roles,
  49. // }
  50. // }
  51. // ToProjectType generates an external types.Project to be shared over REST
  52. func (p *Project) ToProjectType() *types.Project {
  53. roles := make([]*types.Role, 0)
  54. for _, role := range p.Roles {
  55. roles = append(roles, role.ToRoleType())
  56. }
  57. return &types.Project{
  58. ID: p.ID,
  59. Name: p.Name,
  60. Roles: roles,
  61. }
  62. }