Merge pull request #48 from jkaninda/develop
feat: add enable, disable routes health check access link
This commit is contained in:
@@ -131,6 +131,8 @@ gateway:
|
|||||||
rateLimiter: 0
|
rateLimiter: 0
|
||||||
accessLog: "/dev/Stdout"
|
accessLog: "/dev/Stdout"
|
||||||
errorLog: "/dev/stderr"
|
errorLog: "/dev/stderr"
|
||||||
|
## Enable and disable routes healthc check
|
||||||
|
disableHealthCheckStatus: false
|
||||||
## Returns backend route healthcheck errors
|
## Returns backend route healthcheck errors
|
||||||
disableRouteHealthCheckError: false
|
disableRouteHealthCheckError: false
|
||||||
# Disable display routes on start
|
# Disable display routes on start
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ gateway:
|
|||||||
rateLimiter: 0
|
rateLimiter: 0
|
||||||
accessLog: "/dev/Stdout"
|
accessLog: "/dev/Stdout"
|
||||||
errorLog: "/dev/stderr"
|
errorLog: "/dev/stderr"
|
||||||
|
## Enable and disable routes healthc check
|
||||||
|
disableHealthCheckStatus: false
|
||||||
## Returns backend route healthcheck errors
|
## Returns backend route healthcheck errors
|
||||||
disableRouteHealthCheckError: false
|
disableRouteHealthCheckError: false
|
||||||
# Disable display routes on start
|
# Disable display routes on start
|
||||||
@@ -97,7 +99,7 @@ gateway:
|
|||||||
path: /public
|
path: /public
|
||||||
## Rewrite a request path
|
## Rewrite a request path
|
||||||
# e.g rewrite: /store to /
|
# e.g rewrite: /store to /
|
||||||
rewrite: /healthz
|
rewrite: /
|
||||||
destination: https://example.com
|
destination: https://example.com
|
||||||
#DisableHeaderXForward Disable X-forwarded header.
|
#DisableHeaderXForward Disable X-forwarded header.
|
||||||
# [X-Forwarded-Host, X-Forwarded-For, Host, Scheme ]
|
# [X-Forwarded-Host, X-Forwarded-For, Host, Scheme ]
|
||||||
@@ -121,26 +123,18 @@ gateway:
|
|||||||
##### Define route middlewares from middlewares names
|
##### Define route middlewares from middlewares names
|
||||||
## The name must be unique
|
## The name must be unique
|
||||||
## List of middleware name
|
## List of middleware name
|
||||||
middlewares:
|
|
||||||
- api-forbidden-paths
|
|
||||||
- basic-auth
|
|
||||||
# Example of a route | 2
|
|
||||||
- name: Authentication service
|
|
||||||
path: /auth
|
|
||||||
rewrite: /
|
|
||||||
destination: 'http://security-service:8080'
|
|
||||||
healthCheck: /internal/health/ready
|
|
||||||
cors: {}
|
|
||||||
middlewares:
|
middlewares:
|
||||||
- api-forbidden-paths
|
- api-forbidden-paths
|
||||||
# Example of a route | 3
|
# Example of a route | 3
|
||||||
- name: Basic auth
|
- name: Basic auth
|
||||||
path: /protected
|
path: /protected
|
||||||
rewrite: /
|
rewrite: /
|
||||||
destination: 'http://notification-service:8080'
|
destination: https://example.com
|
||||||
healthCheck:
|
healthCheck:
|
||||||
cors: {}
|
cors: {}
|
||||||
middlewares: []
|
middlewares:
|
||||||
|
- api-forbidden-paths
|
||||||
|
- basic-auth
|
||||||
|
|
||||||
#Defines proxy middlewares
|
#Defines proxy middlewares
|
||||||
# middleware name must be unique
|
# middleware name must be unique
|
||||||
@@ -181,17 +175,17 @@ middlewares:
|
|||||||
#
|
#
|
||||||
# Add header to the next request from AuthRequest header, depending on your requirements
|
# Add header to the next request from AuthRequest header, depending on your requirements
|
||||||
# Key is AuthRequest's response header Key, and value is Request's header Key
|
# Key is AuthRequest's response header Key, and value is Request's header Key
|
||||||
# In case you want to get headers from the Authentication service and inject them into the next request's headers
|
# In case you want to get headers from the authentication service and inject them into the next request headers.
|
||||||
headers:
|
headers:
|
||||||
userId: X-Auth-UserId
|
userId: X-Auth-UserId
|
||||||
userCountryId: X-Auth-UserCountryId
|
userCountryId: X-Auth-UserCountryId
|
||||||
# In case you want to get headers from the Authentication service and inject them to the next request's params
|
# In case you want to get headers from the Authentication service and inject them to the next request params.
|
||||||
params:
|
params:
|
||||||
userCountryId: countryId
|
userCountryId: countryId
|
||||||
# The server will return 404
|
# The server will return 403
|
||||||
- name: api-forbidden-paths
|
- name: api-forbidden-paths
|
||||||
type: access
|
type: access
|
||||||
## Forbidden paths
|
## prevents access paths
|
||||||
paths:
|
paths:
|
||||||
- /swagger-ui/*
|
- /swagger-ui/*
|
||||||
- /v2/swagger-ui/*
|
- /v2/swagger-ui/*
|
||||||
|
|||||||
2
goma.yml
2
goma.yml
@@ -14,6 +14,8 @@ gateway:
|
|||||||
rateLimiter: 0
|
rateLimiter: 0
|
||||||
accessLog: "/dev/Stdout"
|
accessLog: "/dev/Stdout"
|
||||||
errorLog: "/dev/stderr"
|
errorLog: "/dev/stderr"
|
||||||
|
## Enable and disable routes healthc check
|
||||||
|
disableHealthCheckStatus: false
|
||||||
## Returns backend route healthcheck errors
|
## Returns backend route healthcheck errors
|
||||||
disableRouteHealthCheckError: false
|
disableRouteHealthCheckError: false
|
||||||
# Disable display routes on start
|
# Disable display routes on start
|
||||||
|
|||||||
@@ -152,6 +152,8 @@ type Gateway struct {
|
|||||||
RateLimiter int `yaml:"rateLimiter" env:"GOMA_RATE_LIMITER, overwrite"`
|
RateLimiter int `yaml:"rateLimiter" env:"GOMA_RATE_LIMITER, overwrite"`
|
||||||
AccessLog string `yaml:"accessLog" env:"GOMA_ACCESS_LOG, overwrite"`
|
AccessLog string `yaml:"accessLog" env:"GOMA_ACCESS_LOG, overwrite"`
|
||||||
ErrorLog string `yaml:"errorLog" env:"GOMA_ERROR_LOG=, overwrite"`
|
ErrorLog string `yaml:"errorLog" env:"GOMA_ERROR_LOG=, overwrite"`
|
||||||
|
// DisableHealthCheckStatus enable and disable routes health check
|
||||||
|
DisableHealthCheckStatus bool `yaml:"disableHealthCheckStatus"`
|
||||||
// DisableRouteHealthCheckError allows enabling and disabling backend healthcheck errors
|
// DisableRouteHealthCheckError allows enabling and disabling backend healthcheck errors
|
||||||
DisableRouteHealthCheckError bool `yaml:"disableRouteHealthCheckError"`
|
DisableRouteHealthCheckError bool `yaml:"disableRouteHealthCheckError"`
|
||||||
//Disable allows enabling and disabling displaying routes on start
|
//Disable allows enabling and disabling displaying routes on start
|
||||||
@@ -288,6 +290,7 @@ func initConfig(configFile string) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Hostname example",
|
Name: "Hostname example",
|
||||||
|
Host: "http://example.localhost",
|
||||||
Path: "/",
|
Path: "/",
|
||||||
Destination: "https://example.com",
|
Destination: "https://example.com",
|
||||||
Rewrite: "/",
|
Rewrite: "/",
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func TestMiddleware(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "forbidden path acces",
|
Name: "forbidden path access",
|
||||||
Type: "access",
|
Type: "access",
|
||||||
Paths: []string{"/", "/admin"},
|
Paths: []string{"/", "/admin"},
|
||||||
Rule: BasicRuleMiddleware{
|
Rule: BasicRuleMiddleware{
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Initialize the routes
|
||||||
func (gatewayServer GatewayServer) Initialize() *mux.Router {
|
func (gatewayServer GatewayServer) Initialize() *mux.Router {
|
||||||
gateway := gatewayServer.gateway
|
gateway := gatewayServer.gateway
|
||||||
middlewares := gatewayServer.middlewares
|
middlewares := gatewayServer.middlewares
|
||||||
@@ -31,9 +32,13 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router {
|
|||||||
DisableRouteHealthCheckError: gateway.DisableRouteHealthCheckError,
|
DisableRouteHealthCheckError: gateway.DisableRouteHealthCheckError,
|
||||||
Routes: gateway.Routes,
|
Routes: gateway.Routes,
|
||||||
}
|
}
|
||||||
// Define the health check route
|
// Routes health check
|
||||||
r.HandleFunc("/healthz", heath.HealthCheckHandler).Methods("GET")
|
if !gateway.DisableHealthCheckStatus {
|
||||||
|
r.HandleFunc("/healthz", heath.HealthCheckHandler).Methods("GET")
|
||||||
|
}
|
||||||
|
// Readiness
|
||||||
r.HandleFunc("/readyz", heath.HealthReadyHandler).Methods("GET")
|
r.HandleFunc("/readyz", heath.HealthReadyHandler).Methods("GET")
|
||||||
|
|
||||||
if gateway.RateLimiter != 0 {
|
if gateway.RateLimiter != 0 {
|
||||||
//rateLimiter := middleware.NewRateLimiter(gateway.RateLimiter, time.Minute)
|
//rateLimiter := middleware.NewRateLimiter(gateway.RateLimiter, time.Minute)
|
||||||
limiter := middleware.NewRateLimiterWindow(gateway.RateLimiter, time.Minute) // requests per minute
|
limiter := middleware.NewRateLimiterWindow(gateway.RateLimiter, time.Minute) // requests per minute
|
||||||
|
|||||||
Reference in New Issue
Block a user