mirror of
https://github.com/hanzo-fi/auth.git
synced 2026-10-30 20:33:21 +00:00
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package sqlstorage
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rsa"
|
|
|
|
"github.com/hanzo-fi/go-libs/v3/logging"
|
|
"github.com/uptrace/bun"
|
|
|
|
"github.com/hanzo-fi/go-libs/v3/bun/bunconnect"
|
|
|
|
auth "github.com/hanzo-fi/auth/pkg"
|
|
"github.com/hanzo-fi/auth/pkg/oidc"
|
|
"github.com/hanzo-fi/go-libs/v3/health"
|
|
"github.com/zitadel/oidc/v2/pkg/op"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
func Module(connectionOptions bunconnect.ConnectionOptions, key *rsa.PrivateKey, debug bool, staticClients ...auth.StaticClient) fx.Option {
|
|
return fx.Options(
|
|
bunconnect.Module(connectionOptions, debug),
|
|
fx.Invoke(func(lc fx.Lifecycle, db *bun.DB) {
|
|
lc.Append(fx.Hook{
|
|
OnStart: func(ctx context.Context) error {
|
|
logging.FromContext(ctx).Info("Migrate tables")
|
|
|
|
return Migrate(ctx, db)
|
|
},
|
|
})
|
|
}),
|
|
fx.Supply(key),
|
|
fx.Supply(staticClients),
|
|
fx.Provide(fx.Annotate(New,
|
|
fx.As(new(oidc.Storage)),
|
|
)),
|
|
health.ProvideHealthCheck(func(storage op.Storage) health.NamedCheck {
|
|
return health.NewNamedCheck("Database", health.CheckFn(storage.Health))
|
|
}),
|
|
)
|
|
}
|