2
0
Alexander Belanger 5 жил өмнө
parent
commit
4f59fbb33f

+ 1 - 0
cmd/app/main.go

@@ -40,6 +40,7 @@ func main() {
 		&models.Cluster{},
 		&models.ClusterCandidate{},
 		&models.ClusterResolver{},
+		&models.AWSInfra{},
 		&ints.KubeIntegration{},
 		&ints.BasicIntegration{},
 		&ints.OIDCIntegration{},

+ 1 - 0
cmd/migrate/main.go

@@ -36,6 +36,7 @@ func main() {
 		&models.Cluster{},
 		&models.ClusterCandidate{},
 		&models.ClusterResolver{},
+		&models.AWSInfra{},
 		&ints.KubeIntegration{},
 		&ints.BasicIntegration{},
 		&ints.OIDCIntegration{},

+ 23 - 0
internal/forms/infra.go

@@ -0,0 +1,23 @@
+package forms
+
+import (
+	"github.com/porter-dev/porter/internal/models"
+)
+
+// 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"`
+}
+
+// ToAWSInfra converts the form to a gorm aws infra model
+func (ce *CreateECRInfra) ToAWSInfra() (*models.AWSInfra, error) {
+	return &models.AWSInfra{
+		Kind:             models.AWSInfraECR,
+		ProjectID:        ce.ProjectID,
+		Status:           models.StatusCreating,
+		AWSIntegrationID: ce.AWSIntegrationID,
+	}, nil
+}

+ 11 - 2
internal/models/infra.go

@@ -16,13 +16,22 @@ const (
 	StatusUpdating InfraStatus = "updating"
 )
 
+// AWSInfraKind is the kind that aws infra can be
+type AWSInfraKind string
+
+// The supported AWS infra kinds
+const (
+	AWSInfraECR AWSInfraKind = "ecr"
+	AWSInfraEKS AWSInfraKind = "eks"
+)
+
 // AWSInfra represents the metadata for an infrastructure type provisioned on
 // AWS
 type AWSInfra struct {
 	gorm.Model
 
 	// The type of infra that was provisioned
-	Kind string `json:"kind"`
+	Kind AWSInfraKind `json:"kind"`
 
 	// The project that this infra belongs to
 	ProjectID uint `json:"project_id"`
@@ -42,7 +51,7 @@ type AWSInfraExternal struct {
 	ProjectID uint `json:"project_id"`
 
 	// The type of infra that was provisioned
-	Kind string `json:"kind"`
+	Kind AWSInfraKind `json:"kind"`
 
 	// Status is the status of the infra
 	Status InfraStatus `json:"status"`

+ 1 - 1
internal/repository/gorm/helpers_test.go

@@ -446,7 +446,7 @@ func initAWSInfra(tester *tester, t *testing.T) {
 	}
 
 	infra := &models.AWSInfra{
-		Kind:      "ecr",
+		Kind:      models.AWSInfraECR,
 		ProjectID: tester.initProjects[0].Model.ID,
 		Status:    models.StatusCreated,
 	}

+ 3 - 3
internal/repository/gorm/infra_test.go

@@ -18,7 +18,7 @@ func TestCreateAWSInfra(t *testing.T) {
 	defer cleanup(tester, t)
 
 	infra := &models.AWSInfra{
-		Kind:      "ecr",
+		Kind:      models.AWSInfraECR,
 		ProjectID: tester.initProjects[0].Model.ID,
 		Status:    models.StatusCreated,
 	}
@@ -40,8 +40,8 @@ func TestCreateAWSInfra(t *testing.T) {
 		t.Errorf("incorrect registry ID: expected %d, got %d\n", 1, infra.Model.ID)
 	}
 
-	if infra.Kind != "ecr" {
-		t.Errorf("incorrect aws infra kind: expected %s, got %s\n", "ecr", infra.Kind)
+	if infra.Kind != models.AWSInfraECR {
+		t.Errorf("incorrect aws infra kind: expected %s, got %s\n", models.AWSInfraECR, infra.Kind)
 	}
 
 	if infra.Status != models.StatusCreated {