registry.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // The infra id, if registry was provisioned with Porter
  17. InfraID uint `json:"infra_id"`
  18. // ------------------------------------------------------------------
  19. // All fields below this line are encrypted before storage
  20. // ------------------------------------------------------------------
  21. GCPIntegrationID uint
  22. AWSIntegrationID uint
  23. DOIntegrationID uint
  24. // A token cache that can be used by an auth mechanism (integration), if desired
  25. TokenCache integrations.RegTokenCache
  26. }
  27. // RegistryExternal is an external Registry to be shared over REST
  28. type RegistryExternal struct {
  29. ID uint `json:"id"`
  30. // The project that this integration belongs to
  31. ProjectID uint `json:"project_id"`
  32. // Name of the registry
  33. Name string `json:"name"`
  34. // URL of the registry
  35. URL string `json:"url"`
  36. // The integration service for this registry
  37. Service integrations.IntegrationService `json:"service"`
  38. // The infra id, if registry was provisioned with Porter
  39. InfraID uint `json:"infra_id"`
  40. }
  41. // Externalize generates an external Registry to be shared over REST
  42. func (r *Registry) Externalize() *RegistryExternal {
  43. var serv integrations.IntegrationService
  44. if r.AWSIntegrationID != 0 {
  45. serv = integrations.ECR
  46. } else if r.GCPIntegrationID != 0 {
  47. serv = integrations.GCR
  48. } else if r.DOIntegrationID != 0 {
  49. serv = integrations.DOCR
  50. }
  51. return &RegistryExternal{
  52. ID: r.ID,
  53. ProjectID: r.ProjectID,
  54. Name: r.Name,
  55. URL: r.URL,
  56. Service: serv,
  57. InfraID: r.InfraID,
  58. }
  59. }