registry.go 1.8 KB

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