helm_repo.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package models
  2. import (
  3. "github.com/porter-dev/porter/internal/models/integrations"
  4. "gorm.io/gorm"
  5. )
  6. // HelmRepo is an integration that can connect to a Helm repository via a
  7. // set of auth mechanisms
  8. type HelmRepo struct {
  9. gorm.Model
  10. // Name given to the Helm repository
  11. Name string `json:"name"`
  12. // The project that this integration belongs to
  13. ProjectID uint `json:"project_id"`
  14. // RepoURL is the URL to the helm repo. This varies based on the integration
  15. // type. For example, for AWS S3 this may be prefixed with s3://, or for
  16. // GCS it may be gs://
  17. RepoURL string `json:"repo_url"`
  18. // ------------------------------------------------------------------
  19. // All fields below this line are encrypted before storage
  20. // ------------------------------------------------------------------
  21. BasicAuthIntegrationID uint
  22. GCPIntegrationID uint
  23. AWSIntegrationID uint
  24. // A token cache that can be used by an auth mechanism (integration), if desired
  25. TokenCache integrations.HelmRepoTokenCache
  26. }
  27. // HelmRepoExternal is an external HelmRepo to be shared over REST
  28. type HelmRepoExternal struct {
  29. ID uint `json:"id"`
  30. // The project that this integration belongs to
  31. ProjectID uint `json:"project_id"`
  32. // Name of the repo
  33. Name string `json:"name"`
  34. RepoURL string `json:"repo_name"`
  35. // The integration service for this registry
  36. Service integrations.IntegrationService `json:"service"`
  37. }
  38. // Externalize generates an external Registry to be shared over REST
  39. func (hr *HelmRepo) Externalize() *HelmRepoExternal {
  40. var serv integrations.IntegrationService
  41. if hr.BasicAuthIntegrationID != 0 {
  42. serv = integrations.HelmRepo
  43. } else if hr.AWSIntegrationID != 0 {
  44. serv = integrations.S3
  45. } else if hr.GCPIntegrationID != 0 {
  46. serv = integrations.GCS
  47. }
  48. return &HelmRepoExternal{
  49. ID: hr.ID,
  50. ProjectID: hr.ProjectID,
  51. Name: hr.Name,
  52. RepoURL: hr.RepoURL,
  53. Service: serv,
  54. }
  55. }