From 40db91aa36869cefe07f005556aff086e994ba3b Mon Sep 17 00:00:00 2001 From: Michael Valdron Date: Fri, 28 Jan 2022 16:44:44 -0500 Subject: [PATCH] Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720 --- index/server/pkg/server/endpoint.go | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/index/server/pkg/server/endpoint.go b/index/server/pkg/server/endpoint.go index cdb8772f..a2cf48a8 100644 --- a/index/server/pkg/server/endpoint.go +++ b/index/server/pkg/server/endpoint.go @@ -143,6 +143,7 @@ func serveDevfile(c *gin.Context) { func serveDevfileStarterProject(c *gin.Context) { devfileName := c.Param("devfileName") starterProjectName := c.Param("starterProjectName") +<<<<<<< HEAD devfileBytes, devfileIndexSchema := fetchDevfile(c, devfileName) if len(devfileBytes) == 0 { @@ -186,6 +187,15 @@ func serveDevfileStarterProject(c *gin.Context) { c.JSON(http.StatusNotFound, gin.H{ "status": fmt.Sprintf("the starter project named %s does not exist in the devfile of %s", starterProjectName, devfileName), }) +======= + devfileBytes := fetchDevfile(c, devfileName) + + if len(devfileBytes) == 0 { + // fetchDevfile was unsuccessful (error or not found) + return + } else { + // TODO: Add fetch start project and set response source. +>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720 } } @@ -312,7 +322,11 @@ func buildIndexAPIResponse(c *gin.Context) { } // fetchDevfile retrieves a specified devfile stored under /registry/**/ +<<<<<<< HEAD func fetchDevfile(c *gin.Context, devfileName string) ([]byte, indexSchema.Schema) { +======= +func fetchDevfile(c *gin.Context, devfileName string) []byte { +>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720 var index []indexSchema.Schema bytes, err := ioutil.ReadFile(indexPath) if err != nil { @@ -321,7 +335,11 @@ func fetchDevfile(c *gin.Context, devfileName string) ([]byte, indexSchema.Schem "error": err.Error(), "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName), }) +<<<<<<< HEAD return make([]byte, 0), indexSchema.Schema{} +======= + return make([]byte, 0) +>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720 } err = json.Unmarshal(bytes, &index) if err != nil { @@ -330,7 +348,11 @@ func fetchDevfile(c *gin.Context, devfileName string) ([]byte, indexSchema.Schem "error": err.Error(), "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName), }) +<<<<<<< HEAD return make([]byte, 0), indexSchema.Schema{} +======= + return make([]byte, 0) +>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720 } // Reuse 'bytes' for devfile bytes, assign empty @@ -353,10 +375,17 @@ func fetchDevfile(c *gin.Context, devfileName string) ([]byte, indexSchema.Schem "error": err.Error(), "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName), }) +<<<<<<< HEAD return make([]byte, 0), devfileIndex } return bytes, devfileIndex +======= + return make([]byte, 0) + } + + return bytes +>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720 } } @@ -364,7 +393,11 @@ func fetchDevfile(c *gin.Context, devfileName string) ([]byte, indexSchema.Schem "status": fmt.Sprintf("the devfile of %s didn't exist", devfileName), }) +<<<<<<< HEAD return bytes, indexSchema.Schema{} +======= + return bytes +>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720 } /** source from serveDevfile **/