-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathroutes_ofrep.go
37 lines (34 loc) · 1.17 KB
/
routes_ofrep.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package api
import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
etag "github.com/pablor21/echo-etag/v4"
middleware2 "github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/api/middleware"
"github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/ofrep"
)
func (s *Server) addOFREPRoutes(cFlagEvalOFREP ofrep.EvaluateCtrl) {
ofrepGroup := s.apiEcho.Group("/ofrep/v1")
ofrepGroup.Use(etag.WithConfig(etag.Config{
Skipper: func(c echo.Context) bool {
switch c.Path() {
case "/ofrep/v1/evaluate/flags", "/ofrep/v1/configuration":
return false
default:
return true
}
},
Weak: false,
}))
// nolint: staticcheck
if len(s.config.AuthorizedKeys.Evaluation) > 0 || len(s.config.APIKeys) > 0 {
ofrepGroup.Use(middleware.KeyAuthWithConfig(middleware.KeyAuthConfig{
Validator: func(key string, _ echo.Context) (bool, error) {
return s.config.APIKeyExists(key), nil
},
ErrorHandler: middleware2.AuthMiddlewareErrHandler,
}))
}
ofrepGroup.POST("/evaluate/flags", cFlagEvalOFREP.BulkEvaluate)
ofrepGroup.POST("/evaluate/flags/:flagKey", cFlagEvalOFREP.Evaluate)
ofrepGroup.GET("/configuration", cFlagEvalOFREP.Configuration)
}