registry.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // The project that this integration belongs to
  13. ProjectID uint `json:"project_id"`
  14. // ------------------------------------------------------------------
  15. // All fields below this line are encrypted before storage
  16. // ------------------------------------------------------------------
  17. GCPIntegrationID uint
  18. AWSIntegrationID uint
  19. }
  20. // RegistryExternal is an external Registry to be shared over REST
  21. type RegistryExternal struct {
  22. ID uint `json:"id"`
  23. // The project that this integration belongs to
  24. ProjectID uint `json:"project_id"`
  25. // Name of the registry
  26. Name string `json:"name"`
  27. // The integration service for this registry
  28. Service integrations.IntegrationService `json:"service"`
  29. }
  30. // Externalize generates an external Registry to be shared over REST
  31. func (r *Registry) Externalize() *RegistryExternal {
  32. var serv integrations.IntegrationService
  33. if r.AWSIntegrationID != 0 {
  34. serv = integrations.ECR
  35. } else if r.GCPIntegrationID != 0 {
  36. serv = integrations.GCR
  37. }
  38. return &RegistryExternal{
  39. ID: r.ID,
  40. ProjectID: r.ProjectID,
  41. Name: r.Name,
  42. Service: serv,
  43. }
  44. }