Skip to content

Commit

Permalink
feat: unauthenticated status endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Jan 2, 2025
1 parent 90cd347 commit 2d6555c
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
65 changes: 65 additions & 0 deletions api/build/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: Apache-2.0

package build

import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/router/middleware/build"
"github.com/sirupsen/logrus"
)

// swagger:operation GET /status/{org}/{repo}/{build} builds GetStatus
//
// Get a build status
//
// ---
// produces:
// - application/json
// parameters:
// - in: path
// name: org
// description: Name of the organization
// required: true
// type: string
// - in: path
// name: repo
// description: Name of the repository
// required: true
// type: string
// - in: path
// name: build
// description: Build number
// required: true
// type: integer
// security:
// - ApiKeyAuth: []
// responses:
// '200':
// description: Successfully retrieved the build
// schema:
// "$ref": "#/definitions/Build"
// '400':
// description: Invalid request payload or path
// schema:
// "$ref": "#/definitions/Build"
// '401':
// description: Unauthorized
// schema:
// "$ref": "#/definitions/Build"
// '404':
// description: Not found
// schema:
// "$ref": "#/definitions/Build"

// GetStatus represents the API handler to return "status", a lite representation of the resource with limited fields for unauthenticated access.
func GetStatus(c *gin.Context) {
// capture middleware values
l := c.MustGet("logger").(*logrus.Entry)
b := build.Retrieve(c)

l.Debug("reading status for build")

c.JSON(http.StatusOK, b)
}
61 changes: 61 additions & 0 deletions api/repo/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: Apache-2.0

package repo

import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"

"github.com/go-vela/server/router/middleware/repo"
)

// swagger:operation GET /status/{org}/{repo} repos GetStatus
//
// Get a repository status
//
// ---
// produces:
// - application/json
// parameters:
// - in: path
// name: org
// description: Name of the organization
// required: true
// type: string
// - in: path
// name: repo
// description: Name of the repository
// required: true
// type: string
// security:
// - ApiKeyAuth: []
// responses:
// '200':
// description: Successfully retrieved the repo
// schema:
// "$ref": "#/definitions/Repo"
// '400':
// description: Invalid request payload or path
// schema:
// "$ref": "#/definitions/Repo"
// '401':
// description: Unauthorized
// schema:
// "$ref": "#/definitions/Repo"
// '404':
// description: Not found
// schema:
// "$ref": "#/definitions/Repo"

// GetStatus represents the API handler to return "status", a lite representation of the resource with limited fields for unauthenticated access.
func GetStatus(c *gin.Context) {
// capture middleware values
l := c.MustGet("logger").(*logrus.Entry)
r := repo.Retrieve(c)

l.Debug("reading status for repo")

c.JSON(http.StatusOK, r)
}
10 changes: 10 additions & 0 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ import (

"github.com/go-vela/server/api"
"github.com/go-vela/server/api/auth"
apiBuild "github.com/go-vela/server/api/build"
apiRepo "github.com/go-vela/server/api/repo"
"github.com/go-vela/server/api/webhook"
"github.com/go-vela/server/router/middleware"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/repo"
Expand All @@ -62,6 +65,13 @@ func Load(options ...gin.HandlerFunc) *gin.Engine {
// Badge endpoint
r.GET("/badge/:org/:repo/status.svg", org.Establish(), repo.Establish(), api.GetBadge)

// Status endpoints
status := r.Group("/status/:org/:repo", org.Establish(), repo.Establish())
{
status.GET("", org.Establish(), repo.Establish(), apiRepo.GetStatus)
status.GET("/:build", org.Establish(), repo.Establish(), build.Establish(), apiBuild.GetStatus)
}

// Health endpoint
r.GET("/health", api.Health)

Expand Down

0 comments on commit 2d6555c

Please sign in to comment.