diff --git a/attachments_test.go b/attachments_test.go index a973b5482..2aa876714 100644 --- a/attachments_test.go +++ b/attachments_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "testing" + "time" "github.com/nyaruka/courier" "github.com/nyaruka/courier/test" @@ -39,7 +40,7 @@ func TestFetchAndStoreAttachment(t *testing.T) { })) defer uuids.SetGenerator(uuids.DefaultGenerator) - uuids.SetGenerator(uuids.NewSeededGenerator(1234)) + uuids.SetGenerator(uuids.NewSeededGenerator(1234, time.Now)) ctx := context.Background() mb := test.NewMockBackend() diff --git a/backends/rapidpro/backend.go b/backends/rapidpro/backend.go index 8bd5570f8..0f21c77ac 100644 --- a/backends/rapidpro/backend.go +++ b/backends/rapidpro/backend.go @@ -624,7 +624,7 @@ func (b *backend) WriteChannelLog(ctx context.Context, clog *courier.ChannelLog) // SaveAttachment saves an attachment to backend storage func (b *backend) SaveAttachment(ctx context.Context, ch courier.Channel, contentType string, data []byte, extension string) (string, error) { // create our filename - filename := string(uuids.New()) + filename := string(uuids.NewV4()) if extension != "" { filename = fmt.Sprintf("%s.%s", filename, extension) } diff --git a/backends/rapidpro/backend_test.go b/backends/rapidpro/backend_test.go index 583feabc4..72b275c89 100644 --- a/backends/rapidpro/backend_test.go +++ b/backends/rapidpro/backend_test.go @@ -1093,7 +1093,7 @@ func (ts *BackendTestSuite) TestSaveAttachment() { knChannel := ts.getChannel("KN", "dbc126ed-66bc-4e28-b67b-81dc3327c95d") defer uuids.SetGenerator(uuids.DefaultGenerator) - uuids.SetGenerator(uuids.NewSeededGenerator(1234)) + uuids.SetGenerator(uuids.NewSeededGenerator(1234, time.Now)) newURL, err := ts.b.SaveAttachment(ctx, knChannel, "image/jpeg", testJPG, "jpg") ts.NoError(err) @@ -1204,7 +1204,7 @@ func (ts *BackendTestSuite) TestWriteMsgWithAttachments() { ctx := context.Background() defer uuids.SetGenerator(uuids.DefaultGenerator) - uuids.SetGenerator(uuids.NewSeededGenerator(1234)) + uuids.SetGenerator(uuids.NewSeededGenerator(1234, time.Now)) knChannel := ts.getChannel("KN", "dbc126ed-66bc-4e28-b67b-81dc3327c95d") clog := courier.NewChannelLog(courier.ChannelLogTypeUnknown, knChannel, nil) diff --git a/backends/rapidpro/contact.go b/backends/rapidpro/contact.go index 94f2328cb..79170e5be 100644 --- a/backends/rapidpro/contact.go +++ b/backends/rapidpro/contact.go @@ -133,7 +133,7 @@ func contactForURN(ctx context.Context, b *backend, org OrgID, channel *Channel, // didn't find it, we need to create it instead contact.OrgID_ = org - contact.UUID_ = courier.ContactUUID(uuids.New()) + contact.UUID_ = courier.ContactUUID(uuids.NewV4()) contact.CreatedOn_ = time.Now() contact.ModifiedOn_ = time.Now() contact.IsNew_ = true diff --git a/backends/rapidpro/msg.go b/backends/rapidpro/msg.go index e51a2522b..32931d928 100644 --- a/backends/rapidpro/msg.go +++ b/backends/rapidpro/msg.go @@ -107,7 +107,7 @@ func newMsg(direction MsgDirection, channel courier.Channel, urn urns.URN, text return &Msg{ OrgID_: dbChannel.OrgID(), - UUID_: courier.MsgUUID(uuids.New()), + UUID_: courier.MsgUUID(uuids.NewV4()), Direction_: direction, Status_: courier.MsgStatusPending, Visibility_: MsgVisible, diff --git a/celery/celery.go b/celery/celery.go index 597b148c9..da5c4b878 100644 --- a/celery/celery.go +++ b/celery/celery.go @@ -39,8 +39,8 @@ const defaultBody = `[[], {}, {"chord": null, "callbacks": null, "errbacks": nul // QueueEmptyTask queues a new empty task with the passed in task name for the passed in queue func QueueEmptyTask(rc redis.Conn, queueName string, taskName string) error { body := base64.StdEncoding.EncodeToString([]byte(defaultBody)) - taskUUID := string(uuids.New()) - deliveryTag := string(uuids.New()) + taskUUID := string(uuids.NewV4()) + deliveryTag := string(uuids.NewV4()) task := Task{ Body: body, @@ -63,7 +63,7 @@ func QueueEmptyTask(rc redis.Conn, queueName string, taskName string) error { Properties: TaskProperties{ BodyEncoding: "base64", CorrelationID: taskUUID, - ReplyTo: string(uuids.New()), + ReplyTo: string(uuids.NewV4()), DeliveryMode: 2, DeliveryTag: deliveryTag, DeliveryInfo: TaskDeliveryInfo{ diff --git a/channel_log.go b/channel_log.go index 84ca74baf..34ca6e4d0 100644 --- a/channel_log.go +++ b/channel_log.go @@ -129,7 +129,7 @@ func NewChannelLog(t ChannelLogType, ch Channel, redactVals []string) *ChannelLo func newChannelLog(t ChannelLogType, ch Channel, r *httpx.Recorder, attached bool, redactVals []string) *ChannelLog { return &ChannelLog{ - uuid: ChannelLogUUID(uuids.New()), + uuid: ChannelLogUUID(uuids.NewV4()), type_: t, channel: ch, recorder: r, diff --git a/channel_log_test.go b/channel_log_test.go index 8778109e4..647b747b5 100644 --- a/channel_log_test.go +++ b/channel_log_test.go @@ -23,7 +23,7 @@ func TestChannelLog(t *testing.T) { })) defer httpx.SetRequestor(httpx.DefaultRequestor) - uuids.SetGenerator(uuids.NewSeededGenerator(1234)) + uuids.SetGenerator(uuids.NewSeededGenerator(1234, time.Now)) defer uuids.SetGenerator(uuids.DefaultGenerator) channel := test.NewMockChannel("fef91e9b-a6ed-44fb-b6ce-feed8af585a8", "NX", "1234", "US", []string{urns.Phone.Prefix}, nil) diff --git a/go.mod b/go.mod index bac282ec6..e8b108573 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/jmoiron/sqlx v1.4.0 github.com/lib/pq v1.10.9 github.com/nyaruka/ezconf v0.3.0 - github.com/nyaruka/gocommon v1.56.4 + github.com/nyaruka/gocommon v1.57.1 github.com/nyaruka/null/v3 v3.0.0 github.com/nyaruka/redisx v0.8.1 github.com/patrickmn/go-cache v2.1.0+incompatible @@ -43,10 +43,10 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.22.0 // indirect - github.com/gofrs/uuid v4.4.0+incompatible // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/s2a-go v0.1.7 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/jellydator/ttlcache/v3 v3.2.0 // indirect diff --git a/go.sum b/go.sum index a0cbfc5ba..45a3e3cb6 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,6 @@ github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4 github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= -github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= -github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -122,8 +120,8 @@ github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8= github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= github.com/nyaruka/ezconf v0.3.0 h1:kGvJqVN8AHowb4HdaHAviJ0Z3yI5Pyekp1WqibFEaGk= github.com/nyaruka/ezconf v0.3.0/go.mod h1:89GUW6EPRNLIxT7lC4LWnjWTgZeQwRoX7lBmc8ralAU= -github.com/nyaruka/gocommon v1.56.4 h1:wE6dnqpFBRRwNO5CLFVb4mnU/uf5g3AX9Ivh7WwxfZQ= -github.com/nyaruka/gocommon v1.56.4/go.mod h1:XDCG6LNrYCH7XfRBDmwue1WMqoJXyltmhTvmBQy2XIk= +github.com/nyaruka/gocommon v1.57.1 h1:s/9WLZAOUNg0dQHZkgpx8qQMUtNJ2mqzxQhdk1+UBn4= +github.com/nyaruka/gocommon v1.57.1/go.mod h1:wa++Yu/8PEP/HwfvXZrGlKZUCPSJAtSJHeuVsWtLOPM= github.com/nyaruka/librato v1.1.1 h1:0nTYtJLl3Sn7lX3CuHsLf+nXy1k/tGV0OjVxLy3Et4s= github.com/nyaruka/librato v1.1.1/go.mod h1:fme1Fu1PT2qvkaBZyw8WW+SrnFe2qeeCWpvqmAaKAKE= github.com/nyaruka/null/v2 v2.0.3 h1:rdmMRQyVzrOF3Jff/gpU/7BDR9mQX0lcLl4yImsA3kw= diff --git a/handlers/clickmobile/handler_test.go b/handlers/clickmobile/handler_test.go index 791750de6..ae3345c2b 100644 --- a/handlers/clickmobile/handler_test.go +++ b/handlers/clickmobile/handler_test.go @@ -221,7 +221,7 @@ func TestOutgoing(t *testing.T) { ) // mock time so we can have predictable MD5 hashes - dates.SetNowSource(dates.NewFixedNowSource(time.Date(2018, 4, 11, 18, 24, 30, 123456000, time.UTC))) + dates.SetNowFunc(dates.NewFixedNow(time.Date(2018, 4, 11, 18, 24, 30, 123456000, time.UTC))) RunOutgoingTestCases(t, ch, newHandler(), outgoingCases, []string{"Password"}, nil) } diff --git a/handlers/telesom/handler_test.go b/handlers/telesom/handler_test.go index 75d71aca7..c83244932 100644 --- a/handlers/telesom/handler_test.go +++ b/handlers/telesom/handler_test.go @@ -172,7 +172,7 @@ func TestOutgoing(t *testing.T) { ) // mock time so we can have predictable MD5 hashes - dates.SetNowSource(dates.NewFixedNowSource(time.Date(2018, 4, 11, 18, 24, 30, 123456000, time.UTC))) + dates.SetNowFunc(dates.NewFixedNow(time.Date(2018, 4, 11, 18, 24, 30, 123456000, time.UTC))) RunOutgoingTestCases(t, defaultChannel, newHandler(), defaultSendTestCases, []string{"Password", "secret"}, nil) } diff --git a/server_test.go b/server_test.go index 12adff1d1..d3c2ae8f1 100644 --- a/server_test.go +++ b/server_test.go @@ -241,7 +241,7 @@ func TestFetchAttachment(t *testing.T) { httpx.SetRequestor(httpMocks) defer uuids.SetGenerator(uuids.DefaultGenerator) - uuids.SetGenerator(uuids.NewSeededGenerator(1234)) + uuids.SetGenerator(uuids.NewSeededGenerator(1234, time.Now)) logger := slog.Default() config := courier.NewDefaultConfig() diff --git a/test/backend.go b/test/backend.go index 7141f433a..8d348265c 100644 --- a/test/backend.go +++ b/test/backend.go @@ -299,7 +299,7 @@ func (mb *MockBackend) GetChannelByAddress(ctx context.Context, cType courier.Ch func (mb *MockBackend) GetContact(ctx context.Context, channel courier.Channel, urn urns.URN, authTokens map[string]string, name string, clog *courier.ChannelLog) (courier.Contact, error) { contact, found := mb.contacts[urn] if !found { - contact = &mockContact{channel, urn, authTokens, courier.ContactUUID(uuids.New())} + contact = &mockContact{channel, urn, authTokens, courier.ContactUUID(uuids.NewV4())} mb.contacts[urn] = contact } return contact, nil @@ -341,7 +341,7 @@ func (mb *MockBackend) SaveAttachment(ctx context.Context, ch courier.Channel, c time.Sleep(time.Millisecond * 2) - return fmt.Sprintf("https://backend.com/attachments/%s.%s", uuids.New(), extension), nil + return fmt.Sprintf("https://backend.com/attachments/%s.%s", uuids.NewV4(), extension), nil } // ResolveMedia resolves the passed in media URL to a media object