Skip to content

Commit

Permalink
Merge branch 'master' of github.com:didi/nightingale
Browse files Browse the repository at this point in the history
  • Loading branch information
710leo committed May 29, 2020
2 parents a727a7f + a366f14 commit 6b646e3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# release version
version=2.3.0
version=2.4.1

CWD=$(cd $(dirname $0)/; pwd)
cd $CWD
Expand Down
4 changes: 4 additions & 0 deletions etc/monapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ redis:
# conn: 500
# read: 3000
# write: 3000

tokens:
- 7dcd606e0462f9df2fea0bf505c9e622

1 change: 1 addition & 0 deletions src/modules/monapi/config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Config struct {
Cleaner cleanerSection `yaml:"cleaner"`
Link linkSection `yaml:"link"`
Notify map[string][]string `yaml:"notify"`
Tokens []string `yaml:"tokens"`
}

type linkSection struct {
Expand Down
4 changes: 3 additions & 1 deletion src/modules/monapi/http/middleware/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"strings"

"github.com/didi/nightingale/src/model"
"github.com/didi/nightingale/src/modules/monapi/config"

"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github.com/toolkits/pkg/errors"
"github.com/toolkits/pkg/slice"
)

func Logined() gin.HandlerFunc {
Expand Down Expand Up @@ -74,7 +76,7 @@ const internalToken = "monapi-builtin-token"
func CheckHeaderToken() gin.HandlerFunc {
return func(c *gin.Context) {
token := c.GetHeader("x-srv-token")
if token != internalToken {
if token != internalToken && !slice.ContainsString(config.Get().Tokens, token) {
errors.Bomb("token[%s] invalid", token)
}
c.Next()
Expand Down
2 changes: 2 additions & 0 deletions src/modules/monapi/http/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func Config(r *gin.Engine) {
v1 := r.Group("/v1/portal").Use(middleware.CheckHeaderToken())
{
v1.POST("/endpoint", endpointImport)
v1.GET("/tree", treeGet)
v1.GET("/endpoints/bynodeids", endpointByNodeIdsGets)
}

transferProxy := r.Group("/api/transfer")
Expand Down

0 comments on commit 6b646e3

Please sign in to comment.