소스 검색

list created infra

Alexander Belanger 5 년 전
부모
커밋
60dd87ee61
4개의 변경된 파일66개의 추가작업 그리고 2개의 파일을 삭제
  1. 14 2
      internal/kubernetes/provisioner/global_stream.go
  2. 1 0
      internal/models/infra.go
  3. 40 0
      server/api/infra_handler.go
  4. 11 0
      server/router/router.go

+ 14 - 2
internal/kubernetes/provisioner/global_stream.go

@@ -109,8 +109,6 @@ func GlobalStreamListener(
 
 		// parse messages from the global stream
 		for _, msg := range xstreams[0].Messages {
-			fmt.Println(msg.Values)
-
 			// parse the id to identify the infra
 			kind, projID, infraID, err := models.ParseWorkspaceID(fmt.Sprintf("%v", msg.Values["id"]))
 
@@ -182,6 +180,20 @@ func GlobalStreamListener(
 						continue
 					}
 				}
+			} else if fmt.Sprintf("%v", msg.Values["status"]) == "error" {
+				infra, err := repo.AWSInfra.ReadAWSInfra(infraID)
+
+				if err != nil {
+					continue
+				}
+
+				infra.Status = models.StatusError
+
+				infra, err = repo.AWSInfra.UpdateAWSInfra(infra)
+
+				if err != nil {
+					continue
+				}
 			}
 
 			// acknowledge the message as read

+ 1 - 0
internal/models/infra.go

@@ -15,6 +15,7 @@ type InfraStatus string
 const (
 	StatusCreating InfraStatus = "creating"
 	StatusCreated  InfraStatus = "created"
+	StatusError    InfraStatus = "error"
 )
 
 // AWSInfraKind is the kind that aws infra can be

+ 40 - 0
server/api/infra_handler.go

@@ -0,0 +1,40 @@
+package api
+
+import (
+	"encoding/json"
+	"net/http"
+	"strconv"
+
+	"github.com/go-chi/chi"
+	"github.com/porter-dev/porter/internal/models"
+)
+
+// HandleListProjectInfra returns a list of infrasa for a project
+func (app *App) HandleListProjectInfra(w http.ResponseWriter, r *http.Request) {
+	projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
+
+	if err != nil || projID == 0 {
+		app.handleErrorFormDecoding(err, ErrProjectDecode, w)
+		return
+	}
+
+	infras, err := app.Repo.AWSInfra.ListAWSInfrasByProjectID(uint(projID))
+
+	if err != nil {
+		app.handleErrorRead(err, ErrProjectDataRead, w)
+		return
+	}
+
+	extInfras := make([]*models.AWSInfraExternal, 0)
+
+	for _, infra := range infras {
+		extInfras = append(extInfras, infra.Externalize())
+	}
+
+	w.WriteHeader(http.StatusOK)
+
+	if err := json.NewEncoder(w).Encode(extInfras); err != nil {
+		app.handleErrorFormDecoding(err, ErrProjectDecode, w)
+		return
+	}
+}

+ 11 - 0
server/router/router.go

@@ -177,6 +177,17 @@ func New(a *api.App) *chi.Mux {
 			),
 		)
 
+		// /api/projects/{project_id}/infra routes
+		r.Method(
+			"GET",
+			"/projects/{project_id}/infra",
+			auth.DoesUserHaveProjectAccess(
+				requestlog.NewHandler(a.HandleListProjectInfra, l),
+				mw.URLParam,
+				mw.ReadAccess,
+			),
+		)
+
 		// /api/projects/{project_id}/provision routes
 		r.Method(
 			"POST",