Skip to content

Commit

Permalink
Support for standard YAML/JSON unmarshaling in configuration loading
Browse files Browse the repository at this point in the history
* Provide an ability to use regular yaml/json unmarshaling for loading configs
  • Loading branch information
vasayxtx committed Feb 11, 2025
1 parent 4a6a2c2 commit 3698c89
Show file tree
Hide file tree
Showing 5 changed files with 428 additions and 190 deletions.
15 changes: 9 additions & 6 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"net/http"
"os"
"time"

"github.com/acronis/go-appkit/httpserver/middleware"
"github.com/acronis/go-appkit/log"
Expand All @@ -38,11 +39,12 @@ func NewJWTParser(cfg *Config, opts ...JWTParserOption) (JWTParser, error) {
}

// Make caching JWKS client.
jwksCacheUpdateMinInterval := cfg.JWKS.Cache.UpdateMinInterval
jwksCacheUpdateMinInterval := time.Duration(cfg.JWKS.Cache.UpdateMinInterval)
if jwksCacheUpdateMinInterval == 0 {
jwksCacheUpdateMinInterval = jwks.DefaultCacheUpdateMinInterval
}
httpClient := idputil.MakeDefaultHTTPClient(cfg.HTTPClient.RequestTimeout, options.loggerProvider, options.requestIDProvider)
httpClient := idputil.MakeDefaultHTTPClient(
time.Duration(cfg.HTTPClient.RequestTimeout), options.loggerProvider, options.requestIDProvider)
jwksClientOpts := jwks.CachingClientOpts{
ClientOpts: jwks.ClientOpts{
LoggerProvider: options.loggerProvider,
Expand Down Expand Up @@ -183,7 +185,7 @@ func NewTokenIntrospector(
return nil, fmt.Errorf("make grpc transport credentials: %w", err)
}
grpcClientOpts := idptoken.GRPCClientOpts{
RequestTimeout: cfg.GRPCClient.RequestTimeout,
RequestTimeout: time.Duration(cfg.GRPCClient.RequestTimeout),
LoggerProvider: options.loggerProvider,
RequestIDProvider: options.requestIDProvider,
UserAgent: libinfo.UserAgent(),
Expand All @@ -195,7 +197,8 @@ func NewTokenIntrospector(
}
}

httpClient := idputil.MakeDefaultHTTPClient(cfg.HTTPClient.RequestTimeout, options.loggerProvider, options.requestIDProvider)
httpClient := idputil.MakeDefaultHTTPClient(
time.Duration(cfg.HTTPClient.RequestTimeout), options.loggerProvider, options.requestIDProvider)

introspectorOpts := idptoken.IntrospectorOpts{
HTTPEndpoint: cfg.Introspection.Endpoint,
Expand All @@ -210,12 +213,12 @@ func NewTokenIntrospector(
ClaimsCache: idptoken.IntrospectorCacheOpts{
Enabled: cfg.Introspection.ClaimsCache.Enabled,
MaxEntries: cfg.Introspection.ClaimsCache.MaxEntries,
TTL: cfg.Introspection.ClaimsCache.TTL,
TTL: time.Duration(cfg.Introspection.ClaimsCache.TTL),
},
NegativeCache: idptoken.IntrospectorCacheOpts{
Enabled: cfg.Introspection.NegativeCache.Enabled,
MaxEntries: cfg.Introspection.NegativeCache.MaxEntries,
TTL: cfg.Introspection.NegativeCache.TTL,
TTL: time.Duration(cfg.Introspection.NegativeCache.TTL),
},
RequireAudience: cfg.JWT.RequireAudience,
ExpectedAudience: cfg.JWT.ExpectedAudience,
Expand Down
Loading

0 comments on commit 3698c89

Please sign in to comment.