Skip to content

Commit

Permalink
fix: fix references after renames; update to a new conduit API
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-vanesyan committed Oct 11, 2024
1 parent 3a0b5be commit 950cf71
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 43 deletions.
17 changes: 8 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ module go.inout.gg/shield
go 1.23.1

require (
github.com/a-h/templ v0.2.747
github.com/a-h/templ v0.2.778
github.com/coreos/go-oidc/v3 v3.11.0
github.com/go-playground/mold/v4 v4.5.0
github.com/go-playground/validator/v10 v10.22.0
github.com/go-playground/validator/v10 v10.22.1
github.com/go-webauthn/webauthn v0.11.2
github.com/google/uuid v1.6.0
github.com/jackc/pgx/v5 v5.7.1
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.9.0
go.inout.gg/conduit v0.0.0-20241005222024-59593f2d1c1c
go.inout.gg/conduit v0.0.0-20241011174716-52bc52d23ab9
go.inout.gg/foundations v0.0.0-20240922153347-0be999149d7c
golang.org/x/crypto v0.27.0
golang.org/x/oauth2 v0.22.0
golang.org/x/text v0.18.0
golang.org/x/crypto v0.28.0
golang.org/x/oauth2 v0.23.0
golang.org/x/text v0.19.0
)

require (
Expand All @@ -39,16 +39,15 @@ require (
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/samber/lo v1.47.0 // indirect
github.com/segmentio/go-camelcase v0.0.0-20160726192923-7085f1e3c734 // indirect
github.com/segmentio/go-snakecase v1.2.0 // indirect
github.com/urfave/cli/v2 v2.27.4 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/sys v0.26.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
36 changes: 18 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/a-h/templ v0.2.747 h1:D0dQ2lxC3W7Dxl6fxQ/1zZHBQslSkTSvl5FxP/CfdKg=
github.com/a-h/templ v0.2.747/go.mod h1:69ObQIbrcuwPCU32ohNaWce3Cb7qM5GMiqN1K+2yop4=
github.com/a-h/templ v0.2.778 h1:VzhOuvWECrwOec4790lcLlZpP4Iptt5Q4K9aFxQmtaM=
github.com/a-h/templ v0.2.778/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w=
github.com/caarlos0/env/v11 v11.1.0 h1:a5qZqieE9ZfzdvbbdhTalRrHT5vu/4V1/ad1Ka6frhI=
github.com/caarlos0/env/v11 v11.1.0/go.mod h1:LwgkYk1kDvfGpHthrWWLof3Ny7PezzFwS4QrsJdHTMo=
github.com/coreos/go-oidc/v3 v3.11.0 h1:Ia3MxdwpSw702YW0xgfmP1GVCMA9aEFWu12XUZ3/OtI=
Expand All @@ -23,8 +23,8 @@ github.com/go-playground/mold/v4 v4.5.0 h1:ZXwf0uZWWxIahglRigOeuFpIuPZxvEGQJ4FxS
github.com/go-playground/mold/v4 v4.5.0/go.mod h1:qUluiWEozHr7EVk1vJzJgW/kWsPwMdpTjx8LV0NEulA=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-webauthn/webauthn v0.11.2 h1:Fgx0/wlmkClTKlnOsdOQ+K5HcHDsDcYIvtYmfhEOSUc=
github.com/go-webauthn/webauthn v0.11.2/go.mod h1:aOtudaF94pM71g3jRwTYYwQTG1KyTILTcZqN1srkmD0=
github.com/go-webauthn/x v0.1.14 h1:1wrB8jzXAofojJPAaRxnZhRgagvLGnLjhCAwg3kTpT0=
Expand Down Expand Up @@ -61,8 +61,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
Expand All @@ -82,22 +82,22 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
go.inout.gg/conduit v0.0.0-20241005222024-59593f2d1c1c h1:oGSiGChsI/gVGI/optS68IPRe55OsOefyPeq6ALTccQ=
go.inout.gg/conduit v0.0.0-20241005222024-59593f2d1c1c/go.mod h1:WKBNQOuiROnR9hJ0oJpLkI7k4+gXS7tnk8Ma+8RRaWQ=
go.inout.gg/conduit v0.0.0-20241011174716-52bc52d23ab9 h1:nYmfjoOrKiCUGAIDWLiyu+RrdN9TQ9WRwK5KUAH0n5Y=
go.inout.gg/conduit v0.0.0-20241011174716-52bc52d23ab9/go.mod h1:qEwpFTi4ynxp2ad6/bFfWdyiZmWcO7+m+XVm+hO/+oI=
go.inout.gg/foundations v0.0.0-20240922153347-0be999149d7c h1:xkhJcJgpXchg5mL4xxzxlmMtFepJLewCUVa81bv03Q4=
go.inout.gg/foundations v0.0.0-20240922153347-0be999149d7c/go.mod h1:/6QZOnj4l6OJz8iogY0uArlkPeUsxz1PTA2EHWotD7Q=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
35 changes: 30 additions & 5 deletions shieldmigrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@ import (
"go.inout.gg/shield/internal/migrations"
)

// Migrator is a database migration utility to roll up and down shield's
// migrations in order.
type Migrator struct {
base conduit.Migrator
base *conduit.Migrator
}

// MigrateOptions specifies options for migration operation.
type MigrateOptions struct {
Steps int
}

// toConduit converts these options to a conduit migration options.
func (opts *MigrateOptions) toConduit() *conduit.MigrateOptions {
return &conduit.MigrateOptions{
Steps: opts.Steps,
}
}

// New creates a new conduit migrator.
func New() *Migrator {
base := conduit.NewMigrator(conduit.NewConfig(func(c *conduit.Config) {
c.Registry = migrations.Registry
Expand All @@ -20,12 +35,22 @@ func New() *Migrator {
return &Migrator{base}
}

func (m *Migrator) Up(ctx context.Context, conn *pgx.Conn) error {
_, err := m.base.Migrate(ctx, conduit.DirectionUp, conn)
func (m *Migrator) Up(ctx context.Context, conn *pgx.Conn, opts *MigrateOptions) error {
var migrateOpts *conduit.MigrateOptions
if opts != nil {
migrateOpts = opts.toConduit()
}

_, err := m.base.Migrate(ctx, conduit.DirectionUp, conn, migrateOpts)
return err
}

func (m *Migrator) Down(ctx context.Context, conn *pgx.Conn) error {
_, err := m.base.Migrate(ctx, conduit.DirectionDown, conn)
func (m *Migrator) Down(ctx context.Context, conn *pgx.Conn, opts *MigrateOptions) error {
var migrateOpts *conduit.MigrateOptions
if opts != nil {
migrateOpts = opts.toConduit()
}

_, err := m.base.Migrate(ctx, conduit.DirectionDown, conn, migrateOpts)
return err
}
2 changes: 1 addition & 1 deletion shieldpasskey/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (h *Handler) HandleStartUserLogin(ctx context.Context, email string) error
}

user := &user{row}
opts, sd, err := h.wa.BeginLogin(user, nil)
_, _, err = h.wa.BeginLogin(user, nil)
if err != nil {
return fmt.Errorf("shield/passkey: unable to initialize passkey login flow: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion shieldpasswordreset/form_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"net/http"

"go.inout.gg/foundations/http/httperror"
"go.inout.gg/shield"
"go.inout.gg/shield/db/driver"
"go.inout.gg/shield/shieldsender"
"go.inout.gg/shield/shieldpassword"
"go.inout.gg/shield/shieldsender"
)

const (
Expand Down
10 changes: 4 additions & 6 deletions shieldsso/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import (
"golang.org/x/oauth2"
)

var _ sso.Provider[any] = (*provider[any])(nil)
var _ shieldsso.Provider[any] = (*provider[any])(nil)

var (
Issuer = "https://accounts.google.com"
)
var Issuer = "https://accounts.google.com"

var (
AuthorizePath = "/sso/google"
Expand All @@ -34,7 +32,7 @@ type provider[T any] struct {
}

// NewProvider creates a new OpenID OAuth2 provider.
func NewProvider[T any](ctx context.Context, cfg *Config) (sso.Provider[T], error) {
func NewProvider[T any](ctx context.Context, cfg *Config) (shieldsso.Provider[T], error) {
oidcProvider, err := oidc.NewProvider(ctx, Issuer)
if err != nil {
return nil, err
Expand All @@ -54,7 +52,7 @@ func NewProvider[T any](ctx context.Context, cfg *Config) (sso.Provider[T], erro
}, nil
}

func (p *provider[T]) UserInfo(ctx context.Context, token *oauth2.Token) (sso.UserInfo[T], error) {
func (p *provider[T]) UserInfo(ctx context.Context, token *oauth2.Token) (shieldsso.UserInfo[T], error) {
// TODO([email protected]): use userInfo.
_, err := p.provider.UserInfo(ctx, p.config.TokenSource(ctx, token))
if err != nil {
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions shieldstrategy/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"net/http"

"go.inout.gg/shield"
"go.inout.gg/shield/shieldstrategy"
"go.inout.gg/shield/shieldstrategy"
"go.inout.gg/shield/shieldtoken"
)

var _ shieldstrategy.Authenticator[any] = (*tokenStrategy[any])(nil)
Expand All @@ -32,7 +33,7 @@ type Token struct {
}

type Issuer[T any] interface {
Issue(ctx context.Context, user *shieldstrategy.User[T]) (*Token, error)
Issue(ctx context.Context, user *shield.User[T]) (*Token, error)
}

type tokenStrategy[T any] struct {
Expand Down
2 changes: 1 addition & 1 deletion shieldtoken/token.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package token
package shieldtoken

import (
"errors"
Expand Down

0 comments on commit 950cf71

Please sign in to comment.