Skip to content

Commit

Permalink
endpoint handlers exported from package for use in mock testing
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Valdron <mvaldron@redhat.com>
  • Loading branch information
michael-valdron committed Jul 29, 2022
1 parent dfd1b91 commit 766511a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
32 changes: 16 additions & 16 deletions index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"gopkg.in/segmentio/analytics-go.v3"
)

// serveRootEndpoint sets up the handler for the root (/) endpoint on the server
// ServeRootEndpoint sets up the handler for the root (/) endpoint on the server
// If html is requested (i.e. from a web browser), the viewer is displayed, otherwise the devfile index is served.
func serveRootEndpoint(c *gin.Context) {
func ServeRootEndpoint(c *gin.Context) {
// Determine if text/html was requested by the client
acceptHeader := c.Request.Header.Values("Accept")
if util.IsHtmlRequested(acceptHeader) {
Expand All @@ -36,11 +36,11 @@ func serveRootEndpoint(c *gin.Context) {
}
}

func serveDevfileIndexV1(c *gin.Context) {
func ServeDevfileIndexV1(c *gin.Context) {
serveDevfileIndex(c, true)
}

func serveDevfileIndexV2(c *gin.Context) {
func ServeDevfileIndexV2(c *gin.Context) {
serveDevfileIndex(c, false)
}

Expand All @@ -62,26 +62,26 @@ func serveDevfileIndex(c *gin.Context, wantV1Index bool) {
buildIndexAPIResponse(c, wantV1Index)
}

func serveDevfileIndexV1WithType(c *gin.Context) {
func ServeDevfileIndexV1WithType(c *gin.Context) {

// Serve the index with type
buildIndexAPIResponse(c, true)
}

func serveDevfileIndexV2WithType(c *gin.Context) {
func ServeDevfileIndexV2WithType(c *gin.Context) {

// Serve the index with type
buildIndexAPIResponse(c, false)
}

// serveHealthCheck serves endpoint `/health` for registry health check
func serveHealthCheck(c *gin.Context) {
// ServeHealthCheck serves endpoint `/health` for registry health check
func ServeHealthCheck(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "the server is up and running",
})
}

func serveDevfileWithVersion(c *gin.Context) {
func ServeDevfileWithVersion(c *gin.Context) {
name := c.Param("name")
version := c.Param("version")
bytes, devfileIndex := fetchDevfile(c, name, version)
Expand Down Expand Up @@ -111,21 +111,21 @@ func serveDevfileWithVersion(c *gin.Context) {
}
}

// serveDevfile returns the devfile content
func serveDevfile(c *gin.Context) {
// ServeDevfile returns the devfile content
func ServeDevfile(c *gin.Context) {
// append the stack version, for endpoint /devfiles/name without version
c.Params = append(c.Params, gin.Param{Key: "version", Value: "default"})
serveDevfileWithVersion(c)
ServeDevfileWithVersion(c)
}

// serveDevfileStarterProject returns the starter project content for the devfile using default version
func serveDevfileStarterProject(c *gin.Context) {
// ServeDevfileStarterProject returns the starter project content for the devfile using default version
func ServeDevfileStarterProject(c *gin.Context) {
c.Params = append(c.Params, gin.Param{Key: "version", Value: "default"})
serveDevfileStarterProjectWithVersion(c)
ServeDevfileStarterProjectWithVersion(c)
}

// serveDevfileStarterProject returns the starter project content for the devfile using specified version
func serveDevfileStarterProjectWithVersion(c *gin.Context) {
func ServeDevfileStarterProjectWithVersion(c *gin.Context) {
devfileName := c.Param("name")
version := c.Param("version")
starterProjectName := c.Param("starterProjectName")
Expand Down
20 changes: 10 additions & 10 deletions index/server/pkg/server/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ func CreateIndexServer() *gin.Engine {
router := gin.Default()

// Registry REST APIs
router.GET("/", serveRootEndpoint)
router.GET("/index", serveDevfileIndexV1)
router.GET("/index/:type", serveDevfileIndexV1WithType)
router.GET("/health", serveHealthCheck)
router.GET("/devfiles/:name", serveDevfile)
router.GET("/devfiles/:name/:version", serveDevfileWithVersion)
router.GET("/devfiles/:name/starter-projects/:starterProjectName", serveDevfileStarterProject)
router.GET("/devfiles/:name/:version/starter-projects/:starterProjectName", serveDevfileStarterProjectWithVersion)
router.GET("/", ServeRootEndpoint)
router.GET("/index", ServeDevfileIndexV1)
router.GET("/index/:type", ServeDevfileIndexV1WithType)
router.GET("/health", ServeHealthCheck)
router.GET("/devfiles/:name", ServeDevfile)
router.GET("/devfiles/:name/:version", ServeDevfileWithVersion)
router.GET("/devfiles/:name/starter-projects/:starterProjectName", ServeDevfileStarterProject)
router.GET("/devfiles/:name/:version/starter-projects/:starterProjectName", ServeDevfileStarterProjectWithVersion)

// Registry REST APIs for index v2
router.GET("/v2index", serveDevfileIndexV2)
router.GET("/v2index/:type", serveDevfileIndexV2WithType)
router.GET("/v2index", ServeDevfileIndexV2)
router.GET("/v2index/:type", ServeDevfileIndexV2WithType)

// Set up a simple proxy for /v2 endpoints
// Only allow HEAD and GET requests
Expand Down

0 comments on commit 766511a

Please sign in to comment.