agent endpoints now protected

This commit is contained in:
Brad Rydzewski 2015-04-30 14:57:53 -07:00
parent 0dc79e5886
commit 779c1c06d3
3 changed files with 18 additions and 0 deletions

View file

@ -115,6 +115,7 @@ func main() {
queue := api.Group("/queue")
{
queue.Use(server.MustAgent())
queue.GET("", server.GetQueue)
queue.POST("/pull", server.PollBuild)

View file

@ -9,6 +9,8 @@ import (
func GetAgentToken(c *gin.Context) {
sess := ToSession(c)
token := &common.Token{}
token.Kind = common.TokenAgent
token.Label = "drone-agent"
tokenstr, err := sess.GenerateToken(token)
if err != nil {
c.Fail(500, err)

View file

@ -213,6 +213,21 @@ func MustAdmin() gin.HandlerFunc {
}
}
func MustAgent() gin.HandlerFunc {
return func(c *gin.Context) {
sess := ToSession(c)
token := sess.GetLogin(c.Request)
if token == nil {
c.AbortWithStatus(401)
return
} else if token.Kind != common.TokenAgent {
c.AbortWithStatus(500)
return
}
c.Next()
}
}
func CheckPull() gin.HandlerFunc {
return func(c *gin.Context) {
u := ToUser(c)