agent endpoints now protected
This commit is contained in:
parent
0dc79e5886
commit
779c1c06d3
3 changed files with 18 additions and 0 deletions
1
drone.go
1
drone.go
|
@ -115,6 +115,7 @@ func main() {
|
|||
|
||||
queue := api.Group("/queue")
|
||||
{
|
||||
queue.Use(server.MustAgent())
|
||||
queue.GET("", server.GetQueue)
|
||||
queue.POST("/pull", server.PollBuild)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue