Skip to content

Commit

Permalink
feat: add Inspect option to registry (#1523)
Browse files Browse the repository at this point in the history
* chore: add alnr to codeowners

* feat: add Inspect option
  • Loading branch information
alnr authored Apr 23, 2024
1 parent 0980607 commit 213cfa5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @zepatrik @hperl
* @zepatrik @hperl @alnr
6 changes: 6 additions & 0 deletions internal/driver/registry_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions ketoctx/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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{},
Expand Down

0 comments on commit 213cfa5

Please sign in to comment.