MCPcopy Index your code
hub / github.com/apache/devlake / RestAuthentication

Function RestAuthentication

backend/server/api/middlewares.go:104–132  ·  view source on GitHub ↗
(router *gin.Engine, basicRes context.BasicRes)

Source from the content-addressed store, hash-verified

102}
103
104func RestAuthentication(router *gin.Engine, basicRes context.BasicRes) gin.HandlerFunc {
105
106 db := basicRes.GetDal()
107 logger := basicRes.GetLogger()
108 if db == nil {
109 panic(fmt.Errorf("db is not initialised"))
110 }
111 apiKeyHelper := apikeyhelper.NewApiKeyHelper(basicRes, logger)
112 return func(c *gin.Context) {
113 path := c.Request.URL.Path
114 // Only open api needs to check api key
115 if !strings.HasPrefix(path, "/rest") {
116 logger.Debug("path %s will continue", path)
117 c.Next()
118 return
119 }
120 path = strings.TrimPrefix(path, "/rest")
121 authHeader := c.GetHeader("Authorization")
122 ok := CheckAuthorizationHeader(c, logger, db, apiKeyHelper, authHeader, path)
123 if !ok {
124 c.Abort()
125 return
126 } else {
127 router.HandleContext(c)
128 c.Abort()
129 return
130 }
131 }
132}
133
134func CheckAuthorizationHeader(c *gin.Context, logger log.Logger, db dal.Dal, apiKeyHelper *apikeyhelper.ApiKeyHelper, authHeader, path string) bool {
135 if authHeader == "" {

Callers 1

CreateApiServerFunction · 0.85

Calls 5

CheckAuthorizationHeaderFunction · 0.85
GetDalMethod · 0.65
GetLoggerMethod · 0.65
DebugMethod · 0.65
NextMethod · 0.65

Tested by

no test coverage detected