registry.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. URL string `json:"url"`
  12. GCPIntegrationID uint `json:"gcp_integration_id"`
  13. AWSIntegrationID uint `json:"aws_integration_id"`
  14. }
  15. // ToRegistry converts the form to a gorm registry model
  16. func (cr *CreateRegistry) ToRegistry() (*models.Registry, error) {
  17. return &models.Registry{
  18. Name: cr.Name,
  19. ProjectID: cr.ProjectID,
  20. GCPIntegrationID: cr.GCPIntegrationID,
  21. AWSIntegrationID: cr.AWSIntegrationID,
  22. }, nil
  23. }
  24. // UpdateRegistryForm represents the accepted values for updating a
  25. // registry (only name for now)
  26. type UpdateRegistryForm struct {
  27. ID uint
  28. Name string `json:"name" form:"required"`
  29. }
  30. // ToRegistry converts the form to a cluster
  31. func (urf *UpdateRegistryForm) ToRegistry(repo repository.RegistryRepository) (*models.Registry, error) {
  32. registry, err := repo.ReadRegistry(urf.ID)
  33. if err != nil {
  34. return nil, err
  35. }
  36. registry.Name = urf.Name
  37. return registry, nil
  38. }