Kaynağa Gözat

parse provisioner cluster like create cluster form

Alexander Belanger 5 yıl önce
ebeveyn
işleme
f2bc9178be

+ 1 - 0
.terraform/environment

@@ -0,0 +1 @@
+ecr-1-3

+ 1 - 0
dashboard/src/main/home/integrations/integration-form/ECRForm.tsx

@@ -40,6 +40,7 @@ export default class ECRForm extends Component<PropsType, StateType> {
   handleSubmit = () => {
   handleSubmit = () => {
     let { awsRegion, awsAccessId, awsSecretKey, credentialsName } = this.state;
     let { awsRegion, awsAccessId, awsSecretKey, credentialsName } = this.state;
     let { currentProject } = this.context;
     let { currentProject } = this.context;
+
     api.createAWSIntegration('<token>', {
     api.createAWSIntegration('<token>', {
       aws_region: awsRegion,
       aws_region: awsRegion,
       aws_access_key_id: awsAccessId,
       aws_access_key_id: awsAccessId,

+ 1 - 1
dashboard/src/shared/api.tsx

@@ -210,7 +210,7 @@ const getProjectRepos = baseApi<{}, { id: number }>('GET', pathParams => {
 
 
 const createAWSIntegration = baseApi<{
 const createAWSIntegration = baseApi<{
   aws_region: string,
   aws_region: string,
-  aws_cluster_id: string,
+  aws_cluster_id?: string,
   aws_access_key_id: string,
   aws_access_key_id: string,
   aws_secret_access_key: string,
   aws_secret_access_key: string,
 }, { id: number }>('POST', pathParams => {
 }, { id: number }>('POST', pathParams => {

+ 35 - 0
internal/kubernetes/provisioner/global_stream.go

@@ -2,8 +2,10 @@ package provisioner
 
 
 import (
 import (
 	"context"
 	"context"
+	"encoding/base64"
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
+	"regexp"
 
 
 	"github.com/porter-dev/porter/internal/repository"
 	"github.com/porter-dev/porter/internal/repository"
 
 
@@ -143,6 +145,39 @@ func GlobalStreamListener(
 
 
 					reg, err := repo.Registry.CreateRegistry(reg)
 					reg, err := repo.Registry.CreateRegistry(reg)
 
 
+					if err != nil {
+						continue
+					}
+				} else if kind == string(models.AWSInfraEKS) {
+					cluster := &models.Cluster{
+						AuthMechanism:    models.AWS,
+						ProjectID:        projID,
+						AWSIntegrationID: infra.AWSIntegrationID,
+					}
+
+					// parse raw data into ECR type
+					dataString, ok := msg.Values["data"].(string)
+
+					if ok {
+						json.Unmarshal([]byte(dataString), cluster)
+					}
+
+					re := regexp.MustCompile(`^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$`)
+
+					// if it matches the base64 regex, decode it
+					caData := string(cluster.CertificateAuthorityData)
+					if re.MatchString(caData) {
+						decoded, err := base64.StdEncoding.DecodeString(caData)
+
+						if err != nil {
+							continue
+						}
+
+						cluster.CertificateAuthorityData = []byte(decoded)
+					}
+
+					cluster, err := repo.Cluster.CreateCluster(cluster)
+
 					if err != nil {
 					if err != nil {
 						continue
 						continue
 					}
 					}