Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: forward config options in middleware #1062

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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