From 213cfa5c7d4a7ebc3957658178a5b1cd24c2669a Mon Sep 17 00:00:00 2001 From: Arne Luenser Date: Tue, 23 Apr 2024 13:11:24 +0200 Subject: [PATCH] feat: add Inspect option to registry (#1523) * chore: add alnr to codeowners * feat: add Inspect option --- .github/CODEOWNERS | 2 +- internal/driver/registry_factory.go | 6 ++++++ ketoctx/options.go | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 5b703308a..286959ca6 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @zepatrik @hperl +* @zepatrik @hperl @alnr diff --git a/internal/driver/registry_factory.go b/internal/driver/registry_factory.go index 536967b06..82ac0b680 100644 --- a/internal/driver/registry_factory.go +++ b/internal/driver/registry_factory.go @@ -96,6 +96,12 @@ func NewDefaultRegistry(ctx context.Context, flags *pflag.FlagSet, withoutNetwor return nil, errors.Wrap(err, "unable to initialize service registry") } + if inspect := options.Inspect(); inspect != nil { + if err := inspect(r.Persister().Connection(ctx)); err != nil { + return nil, errors.Wrap(err, "inspect") + } + } + return r, nil } diff --git a/ketoctx/options.go b/ketoctx/options.go index 27aeb2ecc..c758ecdd9 100644 --- a/ketoctx/options.go +++ b/ketoctx/options.go @@ -7,6 +7,7 @@ import ( "io/fs" "net/http" + "github.com/gobuffalo/pop/v6" "github.com/ory/x/healthx" "github.com/ory/x/logrusx" "github.com/ory/x/otelx" @@ -25,9 +26,11 @@ type ( migrationOpts []popx.MigrationBoxOption readyCheckers healthx.ReadyCheckers extraMigrations []fs.FS + inspect InspectFunc } Option func(o *opts) TracerWrapper func(*otelx.Tracer) *otelx.Tracer + InspectFunc func(*pop.Connection) error ) // WithLogger sets the logger. @@ -96,6 +99,12 @@ func WithReadinessCheck(name string, rc healthx.ReadyChecker) Option { } } +func Inspect(f InspectFunc) Option { + return func(o *opts) { + o.inspect = f + } +} + func (o *opts) Logger() *logrusx.Logger { return o.logger } @@ -128,6 +137,10 @@ func (o *opts) ReadyCheckers() healthx.ReadyCheckers { return o.readyCheckers } +func (o *opts) Inspect() InspectFunc { + return o.inspect +} + func Options(options ...Option) *opts { o := &opts{ contextualizer: &DefaultContextualizer{},