registry.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package forms
  2. import (
  3. "github.com/porter-dev/porter/internal/models"
  4. "github.com/porter-dev/porter/internal/repository"
  5. )
  6. // CreateRegistry represents the accepted values for creating a
  7. // registry
  8. type CreateRegistry struct {
  9. Name string `json:"name" form:"required"`
  10. ProjectID uint `json:"project_id" form:"required"`
  11. GCPIntegrationID uint `json:"gcp_integration_id"`
  12. AWSIntegrationID uint `json:"aws_integration_id"`
  13. }
  14. // ToRegistry converts the form to a gorm registry model
  15. func (cr *CreateRegistry) ToRegistry() (*models.Registry, error) {
  16. return &models.Registry{
  17. Name: cr.Name,
  18. ProjectID: cr.ProjectID,
  19. GCPIntegrationID: cr.GCPIntegrationID,
  20. AWSIntegrationID: cr.AWSIntegrationID,
  21. }, nil
  22. }
  23. // UpdateRegistryForm represents the accepted values for updating a
  24. // registry (only name for now)
  25. type UpdateRegistryForm struct {
  26. ID uint
  27. Name string `json:"name" form:"required"`
  28. }
  29. // ToRegistry converts the form to a cluster
  30. func (urf *UpdateRegistryForm) ToRegistry(repo repository.RegistryRepository) (*models.Registry, error) {
  31. registry, err := repo.ReadRegistry(urf.ID)
  32. if err != nil {
  33. return nil, err
  34. }
  35. registry.Name = urf.Name
  36. return registry, nil
  37. }