Skip to content
Snippets Groups Projects
Commit 2f7bbaab authored by Yordan Kinkov's avatar Yordan Kinkov
Browse files

Apply Authentication middleware to cache service

parent cdef93fa
Branches
Tags
No related merge requests found
......@@ -28,6 +28,7 @@ import (
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/cache/internal/service"
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/cache/internal/service/cache"
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/cache/internal/service/health"
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/auth"
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/graceful"
)
......@@ -103,6 +104,15 @@ func main() {
openapiServer = goaopenapisrv.New(openapiEndpoints, mux, dec, enc, nil, errFormatter, nil, nil)
}
// Apply Authentication middleware if enabled
if cfg.Auth.Enabled {
m, err := auth.NewMiddleware(cfg.Auth.JwkURL, cfg.Auth.RefreshInterval, http.DefaultClient)
if err != nil {
log.Fatalf("failed to create authentication middleware: %v", err)
}
cacheServer.Use(m.Handler())
}
// Configure the mux.
goacachesrv.Mount(mux, cacheServer)
goahealthsrv.Mount(mux, healthServer)
......
......@@ -7,6 +7,7 @@ type Config struct {
Redis redisConfig
Nats natsConfig
Metrics metricsConfig
Auth authConfig
LogLevel string `envconfig:"LOG_LEVEL" default:"INFO"`
}
......@@ -35,3 +36,9 @@ type natsConfig struct {
type metricsConfig struct {
Addr string `envconfig:"METRICS_ADDR" default:":2112"`
}
type authConfig struct {
Enabled bool `envconfig:"AUTH_ENABLED" default:"true"`
JwkURL string `envconfig:"AUTH_JWK_URL"`
RefreshInterval time.Duration `envconfig:"AUTH_REFRESH_INTERVAL" default:"1h"`
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment