finclip-app-manager/router/middleware/appletEcolRole.go

43 lines
1.0 KiB
Go
Raw Normal View History

2023-10-31 14:07:26 +08:00
package middleware
import (
"finclip-app-manager/infrastructure/config"
"gitlab.finogeeks.club/finclip-backend/apm"
"github.com/gin-gonic/gin"
)
var roleVerifyPaths = []string{
"/api/v1/finstore/dev/apps/publishRequest",
"/api/v1/finstore/dev/apps/publishRequestWithdrawal",
"/api/v1/finstore/dev/apps/creation",
}
func VerifyAppletEcolRole(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
//通过这个URL是否配置判断是否是小程序应用市场
//GET方法不检查机构状态
if config.GetConfig().GetRoleURL != "" && c.Request.Method != "GET" {
userID := c.Request.Header.Get("x-consumer-custom-id")
if userID == "" {
log.Errorln("Lack of x-consumer-custom-id")
c.AbortWithStatus(401)
return
}
ok, resp, err := hcaller.HasRole(traceCtx, userID)
if err != nil {
log.Errorf("Failed to call client: %v\n", err)
c.AbortWithStatus(500)
return
}
if !ok {
log.Errorln("Account Forbidden")
c.JSON(403, resp)
c.Abort()
return
}
}
//}
c.Next()
}