diff --git a/context/context.go b/context/context.go index c3fe90f9f..23f93e0bc 100644 --- a/context/context.go +++ b/context/context.go @@ -4,7 +4,7 @@ import ( "context" "sync" - "github.com/distribution/distribution/v3/internal/uuid" + "github.com/google/uuid" ) // instanceContext is a context that provides only an instance id. It is @@ -22,7 +22,7 @@ func (ic *instanceContext) Value(key interface{}) interface{} { // call a random generator from the package initialization // code. For various reasons random could not be available // https://github.com/distribution/distribution/issues/782 - ic.id = uuid.Generate().String() + ic.id = uuid.NewString() }) return ic.id } diff --git a/context/http.go b/context/http.go index f0e5fd518..bcdf29658 100644 --- a/context/http.go +++ b/context/http.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/distribution/distribution/v3/internal/uuid" + "github.com/google/uuid" "github.com/gorilla/mux" log "github.com/sirupsen/logrus" ) @@ -78,7 +78,7 @@ func WithRequest(ctx context.Context, r *http.Request) context.Context { return &httpRequestContext{ Context: ctx, startedAt: time.Now(), - id: uuid.Generate().String(), + id: uuid.NewString(), r: r, } } diff --git a/context/trace.go b/context/trace.go index 8fdb0a93a..2e169f0c5 100644 --- a/context/trace.go +++ b/context/trace.go @@ -5,7 +5,7 @@ import ( "runtime" "time" - "github.com/distribution/distribution/v3/internal/uuid" + "github.com/google/uuid" ) // WithTrace allocates a traced timing span in a new context. This allows a @@ -46,7 +46,7 @@ func WithTrace(ctx context.Context) (context.Context, func(format string, a ...i f := runtime.FuncForPC(pc) ctx = &traced{ Context: ctx, - id: uuid.Generate().String(), + id: uuid.NewString(), start: time.Now(), parent: GetStringValue(ctx, "trace.id"), fnname: f.Name(), diff --git a/go.mod b/go.mod index 7da6e4416..b32650d65 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c github.com/docker/go-metrics v0.0.1 github.com/go-jose/go-jose/v3 v3.0.0 + github.com/google/uuid v1.3.0 github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 github.com/hashicorp/golang-lru/arc/v2 v2.0.5 @@ -51,7 +52,6 @@ require ( github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.5.9 // indirect - github.com/google/uuid v1.3.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/gax-go/v2 v2.7.1 // indirect github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect diff --git a/internal/client/repository_test.go b/internal/client/repository_test.go index 16c14ad2b..b6f4d224c 100644 --- a/internal/client/repository_test.go +++ b/internal/client/repository_test.go @@ -18,12 +18,12 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/context" - "github.com/distribution/distribution/v3/internal/uuid" "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/ocischema" "github.com/distribution/distribution/v3/registry/api/errcode" "github.com/distribution/distribution/v3/testutil" "github.com/distribution/reference" + "github.com/google/uuid" "github.com/opencontainers/go-digest" v1 "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -200,7 +200,7 @@ func TestBlobServeBlobHEAD(t *testing.T) { func TestBlobResume(t *testing.T) { dgst, b1 := newRandomBlob(1024) - id := uuid.Generate().String() + id := uuid.NewString() var m testutil.RequestResponseMap repo, _ := reference.WithName("test.example.com/repo1") m = append(m, testutil.RequestResponseMapping{ @@ -440,7 +440,7 @@ func TestBlobUploadChunked(t *testing.T) { b1[513:1024], } repo, _ := reference.WithName("test.example.com/uploadrepo") - uuids := []string{uuid.Generate().String()} + uuids := []string{uuid.NewString()} m = append(m, testutil.RequestResponseMapping{ Request: testutil.Request{ Method: http.MethodPost, @@ -458,7 +458,7 @@ func TestBlobUploadChunked(t *testing.T) { }) offset := 0 for i, chunk := range chunks { - uuids = append(uuids, uuid.Generate().String()) + uuids = append(uuids, uuid.NewString()) newOffset := offset + len(chunk) m = append(m, testutil.RequestResponseMapping{ Request: testutil.Request{ @@ -555,7 +555,7 @@ func TestBlobUploadMonolithic(t *testing.T) { dgst, b1 := newRandomBlob(1024) var m testutil.RequestResponseMap repo, _ := reference.WithName("test.example.com/uploadrepo") - uploadID := uuid.Generate().String() + uploadID := uuid.NewString() m = append(m, testutil.RequestResponseMapping{ Request: testutil.Request{ Method: http.MethodPost, @@ -663,7 +663,7 @@ func TestBlobUploadMonolithicDockerUploadUUIDFromURL(t *testing.T) { dgst, b1 := newRandomBlob(1024) var m testutil.RequestResponseMap repo, _ := reference.WithName("test.example.com/uploadrepo") - uploadID := uuid.Generate().String() + uploadID := uuid.NewString() m = append(m, testutil.RequestResponseMapping{ Request: testutil.Request{ Method: http.MethodPost, diff --git a/notifications/bridge.go b/notifications/bridge.go index de95907c5..e63aab65b 100644 --- a/notifications/bridge.go +++ b/notifications/bridge.go @@ -6,9 +6,9 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/context" - "github.com/distribution/distribution/v3/internal/uuid" "github.com/distribution/reference" events "github.com/docker/go-events" + "github.com/google/uuid" "github.com/opencontainers/go-digest" ) @@ -219,7 +219,7 @@ func (b *bridge) createEvent(action string) *Event { // createEvent returns a new event, timestamped, with the specified action. func createEvent(action string) *Event { return &Event{ - ID: uuid.Generate().String(), + ID: uuid.NewString(), Timestamp: time.Now(), Action: action, } diff --git a/notifications/bridge_test.go b/notifications/bridge_test.go index 0c10ec049..dba10f274 100644 --- a/notifications/bridge_test.go +++ b/notifications/bridge_test.go @@ -4,12 +4,12 @@ import ( "testing" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/internal/uuid" "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/schema2" v2 "github.com/distribution/distribution/v3/registry/api/v2" "github.com/distribution/reference" events "github.com/docker/go-events" + "github.com/google/uuid" "github.com/opencontainers/go-digest" v1 "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -20,7 +20,7 @@ var ( repo = "test/repo" source = SourceRecord{ Addr: "remote.test", - InstanceID: uuid.Generate().String(), + InstanceID: uuid.NewString(), } ub = mustUB(v2.NewURLBuilderFromString("http://test.example.com/", false)) diff --git a/registry/registry.go b/registry/registry.go index 0f0bb6f2e..98a29eeda 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -23,7 +23,6 @@ import ( "github.com/distribution/distribution/v3/configuration" dcontext "github.com/distribution/distribution/v3/context" "github.com/distribution/distribution/v3/health" - "github.com/distribution/distribution/v3/internal/uuid" "github.com/distribution/distribution/v3/registry/handlers" "github.com/distribution/distribution/v3/registry/listener" "github.com/distribution/distribution/v3/version" @@ -136,10 +135,6 @@ func NewRegistry(ctx context.Context, config *configuration.Configuration) (*Reg return nil, fmt.Errorf("error configuring logger: %v", err) } - // inject a logger into the uuid library. warns us if there is a problem - // with uuid generation under low entropy. - uuid.Loggerf = dcontext.GetLogger(ctx).Warnf - app := handlers.NewApp(ctx, config) // TODO(aaronl): The global scope of the health checks means NewRegistry // can only be called once per process. diff --git a/registry/storage/linkedblobstore.go b/registry/storage/linkedblobstore.go index 31444f642..392d39b06 100644 --- a/registry/storage/linkedblobstore.go +++ b/registry/storage/linkedblobstore.go @@ -10,9 +10,9 @@ import ( "github.com/distribution/distribution/v3" dcontext "github.com/distribution/distribution/v3/context" - "github.com/distribution/distribution/v3/internal/uuid" "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/distribution/reference" + "github.com/google/uuid" "github.com/opencontainers/go-digest" ) @@ -144,7 +144,7 @@ func (lbs *linkedBlobStore) Create(ctx context.Context, options ...distribution. } } - uuid := uuid.Generate().String() + uuid := uuid.NewString() startedAt := time.Now().UTC() path, err := pathFor(uploadDataPathSpec{ diff --git a/registry/storage/purgeuploads.go b/registry/storage/purgeuploads.go index f9bb4447c..e1a876e7f 100644 --- a/registry/storage/purgeuploads.go +++ b/registry/storage/purgeuploads.go @@ -6,8 +6,8 @@ import ( "strings" "time" - "github.com/distribution/distribution/v3/internal/uuid" storageDriver "github.com/distribution/distribution/v3/registry/storage/driver" + "github.com/google/uuid" "github.com/sirupsen/logrus" ) diff --git a/registry/storage/purgeuploads_test.go b/registry/storage/purgeuploads_test.go index fe401cfa1..93aa8a95e 100644 --- a/registry/storage/purgeuploads_test.go +++ b/registry/storage/purgeuploads_test.go @@ -7,16 +7,16 @@ import ( "testing" "time" - "github.com/distribution/distribution/v3/internal/uuid" "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" + "github.com/google/uuid" ) func testUploadFS(t *testing.T, numUploads int, repoName string, startedAt time.Time) (driver.StorageDriver, context.Context) { d := inmemory.New() ctx := context.Background() for i := 0; i < numUploads; i++ { - addUploads(ctx, t, d, uuid.Generate().String(), repoName, startedAt) + addUploads(ctx, t, d, uuid.NewString(), repoName, startedAt) } return d, ctx } @@ -70,7 +70,7 @@ func TestPurgeAll(t *testing.T) { fs, ctx := testUploadFS(t, uploadCount, "test-repo", oneHourAgo) // Ensure > 1 repos are purged - addUploads(ctx, t, fs, uuid.Generate().String(), "test-repo2", oneHourAgo) + addUploads(ctx, t, fs, uuid.NewString(), "test-repo2", oneHourAgo) uploadCount++ deleted, errs := PurgeUploads(ctx, fs, time.Now(), true) @@ -92,7 +92,7 @@ func TestPurgeSome(t *testing.T) { newUploadCount := 4 for i := 0; i < newUploadCount; i++ { - addUploads(ctx, t, fs, uuid.Generate().String(), "test-repo", time.Now().Add(1*time.Hour)) + addUploads(ctx, t, fs, uuid.NewString(), "test-repo", time.Now().Add(1*time.Hour)) } deleted, errs := PurgeUploads(ctx, fs, time.Now(), true) @@ -112,7 +112,7 @@ func TestPurgeOnlyUploads(t *testing.T) { // Create a directory tree outside _uploads and ensure // these files aren't deleted. - dataPath, err := pathFor(uploadDataPathSpec{name: "test-repo", id: uuid.Generate().String()}) + dataPath, err := pathFor(uploadDataPathSpec{name: "test-repo", id: uuid.NewString()}) if err != nil { t.Fatalf(err.Error()) }