Switch to github.com/google/uuid

Signed-off-by: James Hewitt <james.hewitt@uk.ibm.com>
This commit is contained in:
James Hewitt 2023-10-25 12:00:01 +01:00
parent 03a778c1f5
commit ef8651ec2a
No known key found for this signature in database
GPG key ID: EA6C3C654B6193E4
11 changed files with 25 additions and 30 deletions

View file

@ -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
}

View file

@ -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,
}
}

View file

@ -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(),

2
go.mod
View file

@ -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.2 // 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

View file

@ -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,

View file

@ -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,
}

View file

@ -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))

View file

@ -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.

View file

@ -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{

View file

@ -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"
)

View file

@ -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())
}