infra.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package forms
  2. import (
  3. cmdutils "github.com/porter-dev/porter/cli/cmd/utils"
  4. "github.com/porter-dev/porter/internal/models"
  5. )
  6. const randCharset string = "abcdefghijklmnopqrstuvwxyz1234567890"
  7. // CreateECRInfra represents the accepted values for creating an
  8. // ECR infra via the provisioning container
  9. type CreateECRInfra struct {
  10. ECRName string `json:"ecr_name" form:"required"`
  11. ProjectID uint `json:"project_id" form:"required"`
  12. AWSIntegrationID uint `json:"aws_integration_id" form:"required"`
  13. }
  14. // ToAWSInfra converts the form to a gorm aws infra model
  15. func (ce *CreateECRInfra) ToAWSInfra() (*models.AWSInfra, error) {
  16. return &models.AWSInfra{
  17. Kind: models.AWSInfraECR,
  18. ProjectID: ce.ProjectID,
  19. Suffix: cmdutils.StringWithCharset(6, randCharset),
  20. Status: models.StatusCreating,
  21. AWSIntegrationID: ce.AWSIntegrationID,
  22. }, nil
  23. }
  24. // CreateEKSInfra represents the accepted values for creating an
  25. // EKS infra via the provisioning container
  26. type CreateEKSInfra struct {
  27. EKSName string `json:"eks_name" form:"required"`
  28. ProjectID uint `json:"project_id" form:"required"`
  29. AWSIntegrationID uint `json:"aws_integration_id" form:"required"`
  30. }
  31. // ToAWSInfra converts the form to a gorm aws infra model
  32. func (ce *CreateEKSInfra) ToAWSInfra() (*models.AWSInfra, error) {
  33. return &models.AWSInfra{
  34. Kind: models.AWSInfraEKS,
  35. ProjectID: ce.ProjectID,
  36. Suffix: cmdutils.StringWithCharset(6, randCharset),
  37. Status: models.StatusCreating,
  38. AWSIntegrationID: ce.AWSIntegrationID,
  39. }, nil
  40. }
  41. // DestroyECRInfra represents the accepted values for destroying an
  42. // ECR infra via the provisioning container
  43. type DestroyECRInfra struct {
  44. ECRName string `json:"ecr_name" form:"required"`
  45. }
  46. // DestroyEKSInfra represents the accepted values for destroying an
  47. // EKS infra via the provisioning container
  48. type DestroyEKSInfra struct {
  49. EKSName string `json:"eks_name" form:"required"`
  50. }