registry.go 1.5 KB

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