refactor: rename functions
This commit is contained in:
@@ -25,8 +25,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BlocklistMiddleware checks if the request path is forbidden and returns 403 Forbidden
|
// AccessMiddleware checks if the request path is forbidden and returns 403 Forbidden
|
||||||
func (blockList BlockListMiddleware) BlocklistMiddleware(next http.Handler) http.Handler {
|
func (blockList AccessListMiddleware) AccessMiddleware(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
for _, block := range blockList.List {
|
for _, block := range blockList.List {
|
||||||
if isPathBlocked(r.URL.Path, util.ParseURLPath(blockList.Path+block)) {
|
if isPathBlocked(r.URL.Path, util.ParseURLPath(blockList.Path+block)) {
|
||||||
@@ -50,6 +50,7 @@ func NewRateLimiterWindow(requests int, window time.Duration) *RateLimiter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TokenRateLimiter stores tokenRate limit
|
||||||
type TokenRateLimiter struct {
|
type TokenRateLimiter struct {
|
||||||
tokens int
|
tokens int
|
||||||
maxTokens int
|
maxTokens int
|
||||||
@@ -65,7 +66,7 @@ type ProxyResponseError struct {
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// JwtAuth Define struct
|
// JwtAuth stores JWT configuration
|
||||||
type JwtAuth struct {
|
type JwtAuth struct {
|
||||||
AuthURL string
|
AuthURL string
|
||||||
RequiredHeaders []string
|
RequiredHeaders []string
|
||||||
@@ -73,20 +74,20 @@ type JwtAuth struct {
|
|||||||
Params map[string]string
|
Params map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthenticationMiddleware Define struct
|
// AuthenticationMiddleware Define struct
|
||||||
type AuthenticationMiddleware struct {
|
type AuthenticationMiddleware struct {
|
||||||
AuthURL string
|
AuthURL string
|
||||||
RequiredHeaders []string
|
RequiredHeaders []string
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
Params map[string]string
|
Params map[string]string
|
||||||
}
|
}
|
||||||
type BlockListMiddleware struct {
|
type AccessListMiddleware struct {
|
||||||
Path string
|
Path string
|
||||||
Destination string
|
Destination string
|
||||||
List []string
|
List []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthBasic Define Basic auth
|
// AuthBasic contains Basic auth configuration
|
||||||
type AuthBasic struct {
|
type AuthBasic struct {
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
|
|||||||
@@ -53,11 +53,11 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router {
|
|||||||
} else {
|
} else {
|
||||||
// Apply access middleware
|
// Apply access middleware
|
||||||
if accessMiddleware.Type == AccessMiddleware {
|
if accessMiddleware.Type == AccessMiddleware {
|
||||||
blM := middleware.BlockListMiddleware{
|
blM := middleware.AccessListMiddleware{
|
||||||
Path: route.Path,
|
Path: route.Path,
|
||||||
List: accessMiddleware.Paths,
|
List: accessMiddleware.Paths,
|
||||||
}
|
}
|
||||||
r.Use(blM.BlocklistMiddleware)
|
r.Use(blM.AccessMiddleware)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user