Skip to content

Commit

Permalink
feat: forward config options in middleware (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Feb 7, 2023
1 parent 9572b59 commit f3c4386
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion driver/registry_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func (r *RegistryMemory) Tracer() trace.Tracer {
var err error
r.trc, err = otelx.New(r.c.TracingServiceName(), r.Logger(), r.c.TracingConfig())
if err != nil {
r.Logger().WithError(err).Fatalf("Unable to initialize Tracer.")
r.Logger().WithError(err).Fatalf("Unable to initialize Tracer for Oathkeeper.")
}
}
return r.trc.Tracer()
Expand Down
23 changes: 19 additions & 4 deletions middleware/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type (
configFile string
registryAddr *driver.Registry
configProviderAddr *configuration.Provider
configProviderOpts []configx.OptionModifier
}

Option func(*options)
Expand All @@ -59,6 +60,18 @@ func WithLogger(logger *logrusx.Logger) Option {
return func(o *options) { o.logger = logger }
}

// WithConfigOption sets a config option for the middleware. The following
// options will be set regardless:
// - configx.WithContext
// - configx.WithLogger
// - configx.WithConfigFiles
// - configx.DisableEnvLoading
func WithConfigOption(option configx.OptionModifier) Option {
return func(o *options) {
o.configProviderOpts = append(o.configProviderOpts, option)
}
}

// New creates an Oathkeeper middleware from the options. By default, it tries
// to read the configuration from the file "oathkeeper.yaml".
func New(ctx context.Context, opts ...Option) (Middleware, error) {
Expand All @@ -72,10 +85,12 @@ func New(ctx context.Context, opts ...Option) (Middleware, error) {

c, err := configuration.NewKoanfProvider(
ctx, nil, o.logger,
configx.WithContext(ctx),
configx.WithLogger(o.logger),
configx.WithConfigFiles(o.configFile),
configx.DisableEnvLoading(),
append(o.configProviderOpts,
configx.WithContext(ctx),
configx.WithLogger(o.logger),
configx.WithConfigFiles(o.configFile),
configx.DisableEnvLoading(),
)...,
)
if err != nil {
return nil, errors.WithStack(err)
Expand Down

0 comments on commit f3c4386

Please sign in to comment.