Skip to content

Commit

Permalink
chore: one uuid library ought to be enough for everybody
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Feb 7, 2023
1 parent 8d4762c commit 3bf6ec3
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 42 deletions.
4 changes: 2 additions & 2 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (

"github.com/ory/x/tlsx"

"github.com/google/uuid"
"github.com/gofrs/uuid"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -754,7 +754,7 @@ func (p *Config) SecretsDefault(ctx context.Context) [][]byte {
secrets := pp.Strings(ViperKeySecretsDefault)

if len(secrets) == 0 {
secrets = []string{uuid.New().String()}
secrets = []string{uuid.Must(uuid.NewV4()).String()}
p.MustSet(ctx, ViperKeySecretsDefault, secrets)
}

Expand Down
6 changes: 3 additions & 3 deletions examples/go/pkg/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"log"
"strings"

"github.com/google/uuid"
"github.com/gofrs/uuid"

ory "github.com/ory/client-go"
)

func RandomCredentials() (email, password string) {
email = "dev+" + uuid.New().String() + "@ory.sh"
password = strings.ReplaceAll(uuid.New().String(), "-", "")
email = "dev+" + uuid.Must(uuid.NewV4()).String() + "@ory.sh"
password = strings.ReplaceAll(uuid.Must(uuid.NewV4()).String(), "-", "")
return
}

Expand Down
4 changes: 2 additions & 2 deletions examples/go/selfservice/recovery/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"testing"

"github.com/google/uuid"
"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -19,7 +19,7 @@ func TestFunc(t *testing.T) {
publicURL, _ := testhelpers.StartE2EServer(t, "../../pkg/stub/kratos.yaml", nil)
client = pkg.NewSDKForSelfHosted(publicURL)

flow := performRecovery("dev+" + uuid.New().String() + "@ory.sh")
flow := performRecovery("dev+" + uuid.Must(uuid.NewV4()).String() + "@ory.sh")
require.NotEmpty(t, flow.Id)
assert.EqualValues(t, ory.RECOVERYFLOWSTATE_SENT_EMAIL, flow.State)
}
4 changes: 2 additions & 2 deletions examples/go/selfservice/verification/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"testing"

"github.com/google/uuid"
"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -19,7 +19,7 @@ func TestFunc(t *testing.T) {
publicURL, _ := testhelpers.StartE2EServer(t, "../../pkg/stub/kratos.yaml", nil)
client = pkg.NewSDKForSelfHosted(publicURL)

flow := performVerification("dev+" + uuid.New().String() + "@ory.sh")
flow := performVerification("dev+" + uuid.Must(uuid.NewV4()).String() + "@ory.sh")
require.NotEmpty(t, flow.Id)
assert.EqualValues(t, ory.VERIFICATIONFLOWSTATE_SENT_EMAIL, flow.State)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ require (
github.com/google/go-github/v27 v27.0.1
github.com/google/go-github/v38 v38.1.0
github.com/google/go-jsonnet v0.19.0
github.com/google/uuid v1.3.0
github.com/gorilla/sessions v1.2.1
github.com/gtank/cryptopasta v0.0.0-20170601214702-1f550f6f2f69
github.com/hashicorp/consul/api v1.18.0
Expand Down Expand Up @@ -187,6 +186,7 @@ require (
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/pprof v0.0.0-20221010195024-131d412537ea // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions internal/testhelpers/handler_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

"github.com/bxcodec/faker/v3"
"github.com/google/uuid"
"github.com/gofrs/uuid"
"github.com/julienschmidt/httprouter"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -73,7 +73,7 @@ func MockMakeAuthenticatedRequestWithClient(t *testing.T, reg mockDeps, conf *co
}

func MockMakeAuthenticatedRequestWithClientAndID(t *testing.T, reg mockDeps, conf *config.Config, router *httprouter.Router, req *http.Request, client *http.Client, id *identity.Identity) ([]byte, *http.Response) {
set := "/" + uuid.New().String() + "/set"
set := "/" + uuid.Must(uuid.NewV4()).String() + "/set"
if id == nil {
router.GET(set, MockSetSession(t, reg, conf))
} else {
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/oidc/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (s *Strategy) ID() identity.CredentialsType {
}

func (s *Strategy) validateFlow(ctx context.Context, r *http.Request, rid uuid.UUID) (flow.Flow, error) {
if x.IsZeroUUID(rid) {
if rid.IsNil() {
return nil, errors.WithStack(herodot.ErrBadRequest.WithReason("The session cookie contains invalid values and the flow could not be executed. Please try again."))
}

Expand Down
18 changes: 6 additions & 12 deletions x/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@
package x

import (
db "github.com/gofrs/uuid"
"github.com/google/uuid"
"github.com/gofrs/uuid"
)

var EmptyUUID db.UUID
var EmptyUUID uuid.UUID

func NewUUID() db.UUID {
return db.UUID(uuid.New())
func NewUUID() uuid.UUID {
return uuid.Must(uuid.NewV4())
}

func ParseUUID(in string) db.UUID {
id, _ := uuid.Parse(in)
return db.UUID(id)
}

func IsZeroUUID(id db.UUID) bool {
return id == db.UUID{}
func ParseUUID(in string) uuid.UUID {
return uuid.FromStringOrNil(in)
}
17 changes: 0 additions & 17 deletions x/uuid_test.go

This file was deleted.

0 comments on commit 3bf6ec3

Please sign in to comment.