| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- package forms
- import (
- "math/rand"
- "time"
- "github.com/porter-dev/porter/internal/models"
- )
- const randCharset string = "abcdefghijklmnopqrstuvwxyz1234567890"
- // CreateECRInfra represents the accepted values for creating an
- // ECR infra via the provisioning container
- type CreateECRInfra struct {
- ECRName string `json:"ecr_name" form:"required"`
- ProjectID uint `json:"project_id" form:"required"`
- AWSIntegrationID uint `json:"aws_integration_id" form:"required"`
- }
- // ToInfra converts the form to a gorm aws infra model
- func (ce *CreateECRInfra) ToInfra() (*models.Infra, error) {
- return &models.Infra{
- Kind: models.InfraECR,
- ProjectID: ce.ProjectID,
- Suffix: stringWithCharset(6, randCharset),
- Status: models.StatusCreating,
- AWSIntegrationID: ce.AWSIntegrationID,
- }, nil
- }
- // CreateEKSInfra represents the accepted values for creating an
- // EKS infra via the provisioning container
- type CreateEKSInfra struct {
- EKSName string `json:"eks_name" form:"required"`
- ProjectID uint `json:"project_id" form:"required"`
- AWSIntegrationID uint `json:"aws_integration_id" form:"required"`
- }
- // ToInfra converts the form to a gorm aws infra model
- func (ce *CreateEKSInfra) ToInfra() (*models.Infra, error) {
- return &models.Infra{
- Kind: models.InfraEKS,
- ProjectID: ce.ProjectID,
- Suffix: stringWithCharset(6, randCharset),
- Status: models.StatusCreating,
- AWSIntegrationID: ce.AWSIntegrationID,
- }, nil
- }
- // CreateGCRInfra represents the accepted values for creating an
- // GCR infra via the provisioning container
- type CreateGCRInfra struct {
- ProjectID uint `json:"project_id" form:"required"`
- GCPIntegrationID uint `json:"gcp_integration_id" form:"required"`
- }
- // ToInfra converts the form to a gorm aws infra model
- func (ce *CreateGCRInfra) ToInfra() (*models.Infra, error) {
- return &models.Infra{
- Kind: models.InfraGCR,
- ProjectID: ce.ProjectID,
- Suffix: stringWithCharset(6, randCharset),
- Status: models.StatusCreating,
- GCPIntegrationID: ce.GCPIntegrationID,
- }, nil
- }
- // CreateGKEInfra represents the accepted values for creating a
- // GKE infra via the provisioning container
- type CreateGKEInfra struct {
- GKEName string `json:"gke_name" form:"required"`
- ProjectID uint `json:"project_id" form:"required"`
- GCPIntegrationID uint `json:"gcp_integration_id" form:"required"`
- }
- // ToInfra converts the form to a gorm aws infra model
- func (ce *CreateGKEInfra) ToInfra() (*models.Infra, error) {
- return &models.Infra{
- Kind: models.InfraGKE,
- ProjectID: ce.ProjectID,
- Suffix: stringWithCharset(6, randCharset),
- Status: models.StatusCreating,
- GCPIntegrationID: ce.GCPIntegrationID,
- }, nil
- }
- // DestroyECRInfra represents the accepted values for destroying an
- // ECR infra via the provisioning container
- type DestroyECRInfra struct {
- ECRName string `json:"ecr_name" form:"required"`
- }
- // DestroyEKSInfra represents the accepted values for destroying an
- // EKS infra via the provisioning container
- type DestroyEKSInfra struct {
- EKSName string `json:"eks_name" form:"required"`
- }
- // DestroyGKEInfra represents the accepted values for destroying an
- // GKE infra via the provisioning container
- type DestroyGKEInfra struct {
- GKEName string `json:"gke_name" form:"required"`
- }
- // helpers for random string
- var seededRand *rand.Rand = rand.New(
- rand.NewSource(time.Now().UnixNano()))
- // stringWithCharset returns a random string by pulling from a given charset
- func stringWithCharset(length int, charset string) string {
- b := make([]byte, length)
- for i := range b {
- b[i] = charset[seededRand.Intn(len(charset))]
- }
- return string(b)
- }
|