registry.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package models
  2. import (
  3. "github.com/porter-dev/porter/internal/models/integrations"
  4. "gorm.io/gorm"
  5. )
  6. // Registry is an integration that can connect to a Docker image registry via
  7. // a specific auth mechanism
  8. type Registry struct {
  9. gorm.Model
  10. // Name of the registry
  11. Name string `json:"name"`
  12. // URL of the registry
  13. URL string `json:"url"`
  14. // The project that this integration belongs to
  15. ProjectID uint `json:"project_id"`
  16. // ------------------------------------------------------------------
  17. // All fields below this line are encrypted before storage
  18. // ------------------------------------------------------------------
  19. GCPIntegrationID uint
  20. AWSIntegrationID uint
  21. // A token cache that can be used by an auth mechanism (integration), if desired
  22. TokenCache integrations.RegTokenCache
  23. }
  24. // RegistryExternal is an external Registry to be shared over REST
  25. type RegistryExternal struct {
  26. ID uint `json:"id"`
  27. // The project that this integration belongs to
  28. ProjectID uint `json:"project_id"`
  29. // Name of the registry
  30. Name string `json:"name"`
  31. // URL of the registry
  32. URL string `json:"url"`
  33. // The integration service for this registry
  34. Service integrations.IntegrationService `json:"service"`
  35. }
  36. // Externalize generates an external Registry to be shared over REST
  37. func (r *Registry) Externalize() *RegistryExternal {
  38. var serv integrations.IntegrationService
  39. if r.AWSIntegrationID != 0 {
  40. serv = integrations.ECR
  41. } else if r.GCPIntegrationID != 0 {
  42. serv = integrations.GCR
  43. }
  44. return &RegistryExternal{
  45. ID: r.ID,
  46. ProjectID: r.ProjectID,
  47. Name: r.Name,
  48. URL: r.URL,
  49. Service: serv,
  50. }
  51. }